Getting the name of different models tree name.

Getting the name of different models tree name.

hx
Advocate Advocate
1,054 Views
12 Replies
Message 1 of 13

Getting the name of different models tree name.

hx
Advocate
Advocate

how can I use the PowerShape API to get the different model's tree names.

 

as two image below.

 

tree 1.pngtree 2.png

0 Likes
1,055 Views
12 Replies
Replies (12)
Message 2 of 13

hx
Advocate
Advocate

Upload the examples.

0 Likes
Message 3 of 13

luke.edwards.autodesk
Community Manager
Community Manager

Hi, at the moment the API does not support features and components.  Is that what you are referring to?


Luke Edwards
Consulting Services Manager
0 Likes
Message 4 of 13

Anonymous
Not applicable

Do you just need to know how to use a model other than the active one? This snippet will let you toggle between opened models:

 

PSAutomation powerSHAPE = new PSAutomation(Autodesk.ProductInterface.InstanceReuse.UseExistingInstance);
        PSModel model = powerSHAPE.Models["ModelNameHere"];

 

0 Likes
Message 5 of 13

luke.edwards.autodesk
Community Manager
Community Manager

Note that you can only work with the ActiveModel.  I am not sure that the code above will actually switch the windows such that the other model becomes active.  You would need to do something like:

model.Window.MakeActive();

Luke Edwards
Consulting Services Manager
0 Likes
Message 6 of 13

hx
Advocate
Advocate

Hi @luke.edwards.autodesk.

 

I just thick I need Another way to achieve it.

 

1.Click the menu 'Edit'->'Select'-> Select all. to select all the features or compoents.

2.right click the toolBar and select the 'Selection information' button.

3.The selection information dialog show.Selection Information.png

 

 

4. Can I Use macro commands or some methodes to print these information?

 

0 Likes
Message 7 of 13

luke.edwards.autodesk
Community Manager
Community Manager

You can interrogate a solid to find out how many features there are with the command:

print solid['1'].features

(where '1' is the name of the solid).

You can then interrogate the name of each feature

print solid['1'].feature[1].name
print solid['1'].feature[2].name

The features are indexed from 1 above.

 

Does this help?


Luke Edwards
Consulting Services Manager
0 Likes
Message 8 of 13

hx
Advocate
Advocate

Hi @luke.edwards.autodesk

 

The prerequisite for using these commands is had know the name in the tree list first. Whether the entity is solids or assemblies.

 

But now Make me confused is getting the names in tree window.

 

Kind Regards,

Hins Ho.

0 Likes
Message 9 of 13

hx
Advocate
Advocate

Hi @luke.edwards.autodesk

 

If the tree list components are solid, I can use the code to get names and they attributes.

 

But the assembly can not.

 

Code below:

 

Dim sb As New System.Text.StringBuilder
For i As Integer = 0 To PSInstance.ActiveModel.Solids.Count - 1
   sb.AppendLine(PSInstance.ActiveModel.Solids.Item(i).Name)
Next

 

 

Hins Ho

0 Likes
Message 10 of 13

luke.edwards.autodesk
Community Manager
Community Manager

Yes, unfortunately we don't yet support Assemblies in the API.  You would be able to get them with the commands such as the following.  The first gets the number of components and the rest get the names.

print MODEL.COMPONENTS
print COMPONENT[1].NAME
print COMPONENT[2].NAME
...
print COMPONENT[n].NAME

Luke Edwards
Consulting Services Manager
0 Likes
Message 11 of 13

hx
Advocate
Advocate

The command can use return number of compoents.

 

print MODEL.COMPONENTS

 but the print the compoent's name will return no such compoent.

 

print COMPONENT[1].NAME

 No such compoent.png

0 Likes
Message 12 of 13

hx
Advocate
Advocate

hi @luke.edwards.autodesk

 

Can you have any other method to get the component's name?

 

Best regards.

Hins HO.

0 Likes
Message 13 of 13

pedro_babo
Advocate
Advocate

how can I get the number of enteties selected? and theyr names

 

string NumeroComponentes = PowerSHAPE.Execute("print selection.number");

 

this guives one error hou can I get Powershape response to a string?

0 Likes