SolidWorks two times development -04-modify data

Source: Internet
Author: User
Tags modify
Data SolidWorks two times development -04-modify data
The last time you have access to the parameters of the feature, today we will modify it:

To modify the previous steps is not less, when we can read some of the features, we can give him a set of values. Of course, sometimes you need to invoke a specific parameter. SolidWorks is OLE and COM, so get used to it.

You need to call function modifydefinition () to implement changes after you have finished modifying the feature.

We give an example, this example is more comprehensive than the previous, it has a good fault-tolerant guidance mechanism, can be directly to become a stable macro program.

This is the example doubles the length of the base extrude. This example adds an extension to the convex table by one fold.







Dim Swapp as Sldworks.sldworks



Dim Model as ModelDoc2



Dim Component as Component2



Dim Curfeature as feature



Dim Isgood as Boolean



' would become an extrudefeaturedata Object



Dim Featdata as Object



Dim Depth as Double



Dim Selmgr as Selectionmgr











Sub Doublebe ()



}}-->}}-->set Swapp = CreateObject ("Sldworks.application")



}}-->}}-->set Model = Swapp.activedoc



}}-->}}--> ' Make sure this active document is a part



}}-->}}-->if model.gettype <> swdocpart and Model.gettype <> swdocassembly Then

' Here's Swdocpart, swdocassembly my environment didn't pass. I use the MsgBox model.gettype to get integers 1 and 2.



}}-->}}-->msg = "only allowed in Parts or assemblies" ' 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 (the the "in the" group if there are more than one)



}}-->}}--> ' Note, ' That's just a Feature Object



}}-->}}-->set curfeature = selmgr.getselectedobject3 (1)



}}-->}}-->if curfeature is nothing Then



}}-->}}--> ' Tell the user ' this is selected



}}-->}}-->swapp.sendmsgtouser2 "Please select the Base-extrude", Swmbwarning, Swmbok



}}-->}}-->exit Sub



}}-->}}-->end If







}}-->}}--> ' Check the feature ' s type name



}}-->}}--> ' Make sure it's an extrusion



}}-->}}-->if Not curfeature.gettypename = swtnextrusion Then

' Here to use swtnextrusion my environment did not pass, I changed to extrusion just 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 this Component is NULL when accessing the selections of a standalone part. }}-->}}-->if We were calling Accessselections from within a assembly, then model would refer to the top-level docu ment in the assembly and component would refer to the actual part.



}}-->}}-->isgood = featdata.accessselections (Model, Component)



}}-->

}}-->

}}-->}}--> ' Inform the user of an error



}}-->}}-->if not Isgood Then



}}-->}}-->swapp.sendmsgtouser2 "Unable to obtain access selections", Swmbwarning, Swmbok



}}-->}}-->exit Sub



}}-->}}-->end If



}}-->

}}-->

}}-->}}--> ' Make sure the user has selected the base extrude



}}-->}}-->if not Featdata.isbaseextrude Then



}}-->}}-->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 the feature appears in the "Back" state, I do not find the cause of the problem, only in the code execution to the last call

Model.save
Model.rebuild

These two functions are updated automatically.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.