SelectByID2 does not work in a certain case

Hello

I'm in the process of creating a macro and, inevitably, the last step doesn't work. 

I want to select a sketch from a part file. 

When I hard-code the name of the part in which the sketch is located: OK (example: SelectByID2("Nomdelesquisse@partname@assemablage" etc etc )

When I replace the partname with a variable (which comes from Name2) NOT OK. No compiler error but just nothing happens and its passes in a row.  (example: SelectByID2("Nomdelesquisse@&PieceName&@assemablage" etc etc )

Small clarifications: Name2 returns a String and SelectByID2 asks for a name in STRING so that's good (well I think) 

                               My method to catch Name2 works (I placed a spy on my swComp.Name2 line and it's okay I have the socket property) 

 

There you go, if anyone has an idea. I'm a taker!!

 

Thank you very much

Hello

If the line corresponds to your code it is rather:  "Nomdelesquisse@" & partname & "@assemblage"

As it is written, it is interpreted as 100% text

1 Like

Hello and thank you for your answer, 

Then

in this version -  SelectByID2("Nomdelesquisse@partname@assemblage" -: this is the macro record. Indeed, only text.

In this version - SelectByID2("Nomdelesquisse@&PieceName&@assemablage" - : I did concatenate the PieceName variable but it doesn't work.

Also, I can't put a " before and after the &, the compiler doesn't accept. Basically, it's not like in a MsgBox.

In short, it's as if it doesn't want to take a variable, when it's well declared in String.  I must be missing something very stupid but here, I'm sticking. 

 

Hello

Agree with Cyril.f, be careful with the position of the quotation marks.

boolstatus = Part.Extension.SelectByID2(DimensionName & "@" & SketchName & "@" & PartName, "DIMENSION", 0, 0, 0, False, 0, Nothing, 0)

works very well.

Kind regards

But since your part is in an assembly, you must not forget to indicate the identifier of the occurrence of the part, which from memory does not go up in the swComp.Name2, so:

boolstatus = Part.Extension.SelectByID2("Esquisse1@" & PieceName & "-1@Assemblage1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)

for occurrence 1

Kind regards

 

Hello and thank you for your answer, 

The line of code as recorded by VB:

 boolstatus = swModel.Extension.SelectByID2("Contourdecoupe@19XXX000001A-256@Simulateur", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)

Contourdecut is the name of the sketch. He never changes. 

Simulator is the name of the assembly. He never changes. 

Works perfectly. But, 19XXX000001A changes all the time. As well as -256, which is the instance number in the assembly. Hence the placement of a variable. 

--------------------------------------------------------------------------------

What I want (my variable in bold italics underlined):

boolstatus = swModel.Extension.SelectByID2("Contourdecoupe@&Name&@Simulateur", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)

I can add move quotes, it doesn't work. As it is written, absolutely nothing happens. No mistake. Nothing.  

I placed a spy on the Name2 return, the occurrence ID goes back well. 256 as indicated in my too slow to write answer:D

I also tried by creating a second variable containing precisely this number. Nothing either. 

Finally! 

So it's a problem of quotation marks. But also of space. 

Instead of: boolstatus = swModel.Extension.SelectByID2("Contourdecoupe@&Name&@Simulateur", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)

You need:        boolstatus = swModel.Extension.SelectByID2("Contourdecoupe@" & Name & " @Simulateur", "SKETCH", 0, 0, 0, False, 0, Nothing, 0) 

And not:      boolstatus = swModel.Extension.SelectByID2("Contourdecoupe@"&Name&"@Simulateur", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)

We learn more every day! 

Thank you for your advice:)

 

 

So my memory was failing, the identifier of the occurrence of the part goes back well...

FYI, for this to work, your pieces must also be in resolved mode.

Kind regards

Hello

Are you sure you have chosen the best answer?

Cyril.f's has everything you need, the quotation marks, the spaces...

Kind regards

3 Likes