This is a message to the API guru's out there. I'm working on the next version of XMLPropWorks as discussed at
formatting link
Anyway, the feature I'm currently working on is the ability to assign custom properties to a part within an assembly. What I'm looking for help with is identifying the part that the user has selected. I've gone through the documentation and there are plenty of functions to select a part by knowing it's name.
What I want to know is how do I determine the name of the component that has had a feature selected by the user?
Another option would be to force the user to edit the part within the confines of the assembly to be able to set the custom properties. In this case, how do I identify the edited part?
Thanks
chris
NOTE: Please accept my apologies if you see multiple copies of this. I'm behind a firewall at work and am not certain that Agent is posting messages so I've posted this one from Google Groups.
On Jul 26, 9:19 am, " snipped-for-privacy@movingpart.com" wrote:
Never mind.
This is what I'm looking for (from the API help)
'Get Selected Objects and Types Example (VB) 'This example shows how to determine what is currently selected.
'----------------------------------------------- ' Problem: ' There are many features and selectable ' entities within the SolidWorks software. In most cases, ' it is obvious as to what is selected but ' sometimes it is not clear or it is ambiguous. ' ' This code sample is a diagnostic tool ' to determine what is currently selected. It shows ' several techniques and methods to get a reference ' to what is selected. ' ' Preconditions: ' (1) Document is open. ' (2) Something is selected. ' ' Postconditions: ' None ' ' NOTE: Not all features have an associated *FeatureData object. ' '-----------------------------------------------
Sub main() Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swSelMgr As SldWorks.SelectionMgr Dim swSelObj As Object Dim swFeat As SldWorks.Feature Dim swEnt As SldWorks.Entity Dim swBody As SldWorks.Body2 Dim swSelComp As SldWorks.Component2 Dim swSelModel As SldWorks.ModelDoc2 Dim nSelType As Long Dim sFeatName As String Dim bRet As Boolean
' Disables VB's implicit error on QI On Error Resume Next
Set swApp = CreateObject("SldWorks.Application") Set swModel = swApp.ActiveDoc Set swSelMgr = swModel.SelectionManager
' Could either have a feature or entity selected ' ' Do not try to get entity directly ' from feature because feature may be NULL. Instead, ' use SelectionMgr. Set swFeat = swSelMgr.GetSelectedObject5(1) Set swEnt = swSelMgr.GetSelectedObject5(1) Set swBody = swSelMgr.GetSelectedObject5(1) Set swSelObj = swSelMgr.GetSelectedObject5(1)
Set swSelComp = swSelMgr.GetSelectedObjectsComponent2(1)
If Not swFeat Is Nothing Then Debug.Print "Feature = " + swFeat.Name + " [" + swFeat.GetTypeName + "]" End If
If Not swBody Is Nothing Then Debug.Print " Body selected" End If
If swFeat Is Nothing And _ swEnt Is Nothing And _ swBody Is Nothing And _ Not swSelObj Is Nothing Then Debug.Print " Unknown object" End If
' Could not get component from SelectionMgr ' so try and get component through Entity If swSelComp Is Nothing Then Set swSelComp = swEnt.GetComponent End If
If Not swSelComp Is Nothing Then Set swSelModel = swSelComp.GetModelDoc
Debug.Print "CompName = " + swSelComp.Name2 Debug.Print "ModelPath = " + swSelModel.GetPathName End If End Sub '------------------------------------------
Selection sorting can be quite tedious, especially in assemblies. Often, a programmer wants to allow multiple ways of selection (by tree, entity, component). One ends up using a lot of calls to "get body from face", or "get sketch from selected line" or "get part from component ...from feature or face!".
Look at the "Density Manager" macro. It's getting a bit long in tooth, but I recall doing a lot of selection sorting in the program.
Look up error handling on the web somewhere (or maybe even in VB help). You can write code that tells VB how to handle errors (i.e. "On Error Goto MyErrorHandler")
PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.