SolidWorks two times Development -03-access feature data

Source: Internet
Author: User
Visit | Data SolidWorks two times development -03-access feature data
' Coder Arden
' Filename:getchoosed.swp
' Date:2005-03-22
' Used to get ' simple hole infomation DEP & Dia
' Finished lucky!!
'------------------------------------------------------------

Option Explicit
Dim Swapp as Sldworks.sldworks
Dim Model as ModelDoc2
Dim Curfeature as feature
Dim Boolstatus as Boolean
Dim Featdata as SimpleHoleFeatureData2 ' declares a simple straight hole object
Dim Component as Component2
Dim DEP as Double
Dim Dia as Double
Dim Selmgr as Selectionmgr
Dim Ncount as Integer



Sub getselected ()

Set Swapp = Application.sldworks

Set Model = Swapp.activedoc

Set selmgr = Model.selectionmanager

Set curfeature = selmgr.getselectedobject5 (1) ' Gets the first feature currently selected

MsgBox curfeature. Name

Set featdata = curfeature. Getdefinition ' Get the definition of the feature

Boolstatus = Featdata. Accessselections (Model, component) ' can access the data

ncount = Featdata. Getfeaturescopebodiescount

MsgBox ncount


DEP = Featdata. Depth
Dia = Featdata. Diameter

MsgBox Dia & "*" & DEP

' MsgBox ' Error Arden ' can be used in SolidWorks Swapp.sendmsgtouser2
' Featdata. Releaseselectionaccess
Model.save
Model.editrebuild
End Sub

**********************************************

Before running the above program, suppose you choose a simple straight hole feature. Then get this hole de some parameters.

depth, diameter and so on.

SolidWorks's API is e-text. The introduction is also detailed, and there are a lot of example. You can look at the code more.

To access a feature, you need to go through the steps:

Define a Feature object: Dim....as ...

Get this feature: for example, using GETSELECTEDOBJECT5 and Selectebyid ...

To be defined: getdefinition

For access: accessselections

The above program does not have the IF choice fault-tolerant mechanism that needs to be added on.


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.