selected objects full name

192 views
Skip to first unread message

tbischel

unread,
Sep 3, 2009, 7:23:05 PM9/3/09
to SolidWorks-API
Hi,
I'm trying to get the name of a selected object as displayed when
you hover over it... I've found getentityname() which works for the
first half of the name, but I can't find the component its attached
to.
I guess a corresponding question, given a face/vertex/edge, can I
find the associated component?

Chris

unread,
Sep 4, 2009, 9:14:39 AM9/4/09
to SolidWorks-API
tbiscel,
I'm not exactly sure what you are trying to do. If I'm in an assembly
and want the name of the selected part, I use something like:

Set swSelComp = swSelMgr.GetSelectedObjectsComponent3(1, 0) 'Sets
the selected object as the part to be mated
swSelCompName = swSelComp.Name2 'Gets
the name of the selected part

If I'm in a drawing and have selected a note or balloon and want to
know what it is attached to, I have used:

vAttEntArr = swAnn.GetAttachedEntities3 'Get the
entity (edge, surface, etc) that the balloon is attached to
Set swEnt = vAttEntArr(0) 'Entity the
balloon is attached to
Set swComp = swEnt.GetComponent 'Component the
entity is part of
Set swCompModel = swComp.GetModelDoc 'Modeldoc of
the component

Is either of these what you are looking for?

Chris

tbischel

unread,
Sep 4, 2009, 2:21:56 PM9/4/09
to SolidWorks-API
So I think this gets me most of the way there (my code here is the C#
equiv)... if I have selected say an edge...

object selected = selmgr.GetSelectedObject6(i, -1);
if((int)swSelectType_e.swSelEDGES == (int)selmgr.GetSelectedObjectType3
(i, -1))
{
Edge edge = selected as Edge;
Entity entity = selected as Entity;
name = ((edge.GetBody() as Body2).Name + " of " +
(entity.GetComponent() as Component2).Name2);
}

alternatively, there is the modeldoc2 function model.GetEntityName
(entity) that seems to return useful results sometimes. I haven't
been able to figure out how to label a vertex.
Reply all
Reply to author
Forward
0 new messages