SOLIDWORKS Secondary Development-04-Modify Data

xiaoxiao2021-03-05  20

SOLIDWORKS Secondary Development-04-Modify Data

The last parameters of the feature have been accessed, today we will modify it:

The steps to modify can't be less. When we can read some feature, we can set some values ​​to him. Of course, sometimes you need to call a specific parameter. SolidWorks is OLE and COM, so it is used to it.

Call the function modifydefinition () when modifying the feature.

We give an example that this example is comprehensive than the previous, it has a good fault-tolerant boot mechanism, which can be used directly into a stable macro.

This example doubles the length of the tensile boss at double the length of the tensile boss.

DIM SWAPP As SLDWORKS.SLDWORKS

Dim model as modeldoc2

Dim Component As Component2

DIM Curfeature As Feature

Dim isgood as boolean

'Will Become An ExtrudefeatureData Object

Dim featdata as object

DIM Depth as Double

DIM SELMGR AS SelectionMgr

Sub doublebe ()

Set swapp = creteObject ("SLDWorks.Application")

Set model = swapp.activedoc

'Make Sure That The Active Document Is A Part

If MODEL.GETTYPE <> SWDOCPART and model.gettype <> SWDocassembly

'Swdocpart here, SWDocassembly, my environment is not passed. I use msgbox model.gettype's clumsy approach to get an integer of 1 and 2

Msg = "only allowed on parts or assembly" define message

Style = vbokonly 'Ok Button ONLY

Title = "Error" 'Define Title

Call Msgbox (MSG, Style, Title) 'Display Error Message

Exit Sub 'EXIT THIS Program

END IF

'Get the selection manager

SET SELMGR = Model.SelectionManager

'Get the selected object (First in the groupiffness "

'Note That At this Point Curfeature IS Just A Feature Object

Set Curfeature = SELMGR.GetSelectedObject3 (1)

IF Curfeature Is Nothing Then

'Tell the user thing nothing is success

Swapp.sendmsgtouser2 "please select the base-extrude", SWMBWARNING, SWMBOK

EXIT SUB

END IF

'Check the feature's type name

'Make Sure IT IS An Extrusion

If not curfeature.gettypename = swtnextrusion then 'here uses the SWTNEXTRISTION I have not passed, I changed to Extrusion OK

Swapp.sendmsgtouser2 "please select the base-extrude", SWMBWARNING, SWMBOK

EXIT SUB

END IF

'Get the Extrusion's Feature Data

Set featdata = curfeature.getDefinition

'Get the access Selections for the feature data

'Note That Component Is Null When Accessing The Selections of A Standalone Part.

IF WEERE CALLING AccessSelections from With, The model woulder..

IsGood = featdata.accessselection (model, component)

'Inform the user of an error

IF not isgood then

Swapp.sendmsgtouser2 "Unable to Obtain Access Selection", SWMBWARNING, SWMBOK

EXIT SUB

END IF

'Make Sure The User Has Selected The Base Extrude

IF not featdata.isbaseextrude the

Swapp.sendmsgtouser2 "please select the base-extrude", SWMBWARNING, SWMBOK

Featdata.ReleaseSelectionAccess

EXIT SUB

END IF

'Change the Depth of this Extrusion To Double ITS Previous Depth

Depth = featdata.getDepth (True)

Featdata.SetDepth true, depth * 2

'Implement the changes to the feature

Isgood = Curfeature.ModifyDefinition (Featdata, Model, Component)

'If the modify definition failed

IF not isgood then

Swapp.sendmsgtouser2 "Unable to modify feature data", SWMBWARNING, SWMBOK

'Release The AccessSelections

Featdata.ReleaseSelectionAccess

END IF

End Sub

If a "return" state occurs, I haven't found the problem since I haven't found the problem, and I can only execute the code to the last call.

Model.save model.rebuild

These two functions are automatically updated.

转载请注明原文地址:https://www.9cbs.com/read-39286.html

New Post(0)