Macro select a named face of a part in an assembly

To be able to add a constraint, in a macro I need to select a named face of a part in an assembly, I have something like below, but it doesn't work

' boolstat = swModelDocExt.SelectByID2("Fond@col_60-1@ass", "PLANE", 0, 0, 0, True, 1, Nothing, swSelectOptionDefault)

Can anyone help me?

thank you in advance

AF

 

Hi, do you know the name of the play?

Yes

It is: col_60-1

ASS is the name of the assembly

the name of the face is: Fond

I just saw that your line starts with an apostrophe: it should be removed because it's the sign for comments and it doesn't know what is written after it!

   ' boolstat = swModelDocExt.SelectByID2("Fond@col_60-1@ass", "PLANE", 0, 0, 0, True, 1, Nothing, swSelectOptionDefault)

=>

 boolstat = swModelDocExt.SelectByID2("Fond@col_60-1@ass", "PLANE", 0, 0, 0, True, 1, Nothing, swSelectOptionDefault)

Correct

but it was a try that  doesn't work so I had put it in the comments

CDLT

 

Is the guy good?

You indicate a plane "PLANE" while you talk about a face "FACE"

http://help.solidworks.com/2015/English/api/swconst/SOLIDWORKS.Interop.swconst~SOLIDWORKS.Interop.swconst.swSelectType_e.html

Interesting information here too:

http://help.solidworks.com/2015/English/api/sldworksapi/Get_Component_Face_By_Name_Example_VB.htm

 

In fact, here they say that this statement doesn't work and that you have to use GetEntityByName and then Select4 

https://forum.solidworks.com/thread/62936

An example of this GetEntityByName statement :

http://help.solidworks.com/2014/English/api/sldworksapi/Get_Component_Name_From_Selected_Entity_Example_VB.htm

Ok I'll look into all this

but my goal is not to have human intervention

CDLT

1 Like

With GetEntityByName  , there is no question of human intervention! And I think it will work better than "SelectByID2".

Indeed the solution is in this example:

http://help.solidworks.com/2015/English/api/sldworksapi /Get_Component_Face_By_Name_Example_VB.htm

I have attached part of my program

CDLT


select_component_face_by_name_example_vba.txt

And the program works now?

If not, which line is in error and what is the error?

yes I wasn't clear

the program tip works

Thank you

AF