Get name of current assembly, when editing sub-assemblies

Get name of current assembly, when editing sub-assemblies

pball
Mentor Mentor
500 Views
1 Reply
Message 1 of 2

Get name of current assembly, when editing sub-assemblies

pball
Mentor
Mentor

I have a script which currently references ThisApplication.ActiveDocument which is fine if you are in the top level assembly. But when I go into a sub-assembly to edit it, I would like the script to get the name of the sub-assembly.

 

So is there a simple way to get the name of the sub-assembly you are currently editing?

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Accepted solutions (1)
501 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Accepted solution

This scriptlet will give the name of the object you are currently editing.

1. - Checks if the current document is an assembly. If it is given a message and exits.

2. - Displays the name of the document currently being edited
A Sub-assembly o Part that is being edited) If you're not editing anything,
gives the name of the parent assembly.

** You should now catch the type of document being edited to make other functions on it, for example.

Public Sub DameNombre()
    If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then
        MsgBox ("Macro only for Assembly")
        End
    End If
      
    If ThisApplication.ActiveEditDocument.DocumentType = kAssemblyDocumentObject Then
        MsgBox ("Sub-Assembly name = " & ThisApplication.ActiveEditDocument.DisplayName)
    Else
        MsgBox ("Part name = " & ThisApplication.ActiveEditDocument.DisplayName)
    End If
End Sub