AnsweredAssumed Answered

component2.name2 doesn't return hierarchy

Question asked by Gertjan Van Dijk on Oct 23, 2018
Latest reply on Oct 24, 2018 by Gennadiy Tsybikov

I am working on reworking out companies' in-house solidworks toolbar to a newer, easier to maintain version, but i am being stumped by a specific API call.

 

One process in the toolbar requires me to select the origin of a component X levels deep into subassemblies on a drawing, and since i want to attach a Balloon to it, this needs to happen with "SelectByID2".

 

now; to create the selection string, i have a small utility method that is used on several locations:

 

[quote]

StringBuilder builder = new StringBuilder("Point1@Origin@");

builder.Append(swView.RootDrawingComponent.Name);

builder.Append("@" + swView.Name);

 

 

string[] fileStructure = comp.Name2.Split('/');

 

 

builder.Append("/" + fileStructure[0]);

 

 

builder.Append("@" + swView.RootDrawingComponent.Name.Split('-')[0]);

 

 

for (int i = 1; i < fileStructure.Count(); i++)

{

builder.Append("/" + fileStructure[i] + "@");

builder.Append(fileStructure[i - 1].Split('-')[0]);

}

return builder.ToString();

[/quote]

 

The problem in this method lies in  "Component2::Name2" it only returns the components' own name with the indexer, not the entire hierarchy that the API documentation claims it should return.

I would expect the call to return "Assem4-1/phantom-1/Part1-1", but i only get "Part1-1".

 

I have confirmed that i indeed am referencing the correct component.

 

Trying to build my own full name, i called "Component2::GetParent", but the debugger claims that this method does not exist, despite suggesting it during autocomplete.

To make things even more interesting, "Component2::GetSelectByIDString" does realize that the current component is in an assembly, as it returns "Part1-1@phantom", but it fails to realize that "phantom" itself is a subassembly.

 

Even stranger is the fact that this exact same call in VB.Net (same assembly, same references, same method of reaching the component) i fact does produce the desired and expected result of "Assem4-1/phantom-1/Part1-1"

 

 

 

 

The solidworks.interop.sldworks dll version in use is 25.2.0.52; i am unable to change this, and the language in use is C#; this also won't change.

 

Does anyone have any insight over the difference between the languages, or a different method of attaching notes? (i tried component.select, this is not accepted by the API)

Outcomes