Monday, 20 October 2014

Part tagging

If you have read my previous post on tagging components in the drawing you will like this one. The following code lets you select parts in the assembly and prompt for occurrence name (used as tags for our equipment).

You can select as many parts as you want and it will prompt for a new value and change it for all of them in the order you have selected them.





The dialog shows the current occurrence value and if you click cancel even after the value was changed it reverts the occurrence name to default with the first available index number.



No you can use the Component Tags Post to show them in the drawing.

Here is the code, you need to have part selection filter in the assembly first active.

' Declare current assembly
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument

' Set a reference to the assembly component definintion.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oAsmDoc.ComponentDefinition

'Get the selection set
Dim selSet As SelectSet
selSet = oAsmDoc.SelectSet

'loop trough each selected part
For Each obj In selSet
            oTagOcc = InputBox("Enter Tag No: ", "Tag Prompt", obj.Name)
            obj.Name = oTagOcc

Next

EDIT:

I have updated the code, here's the new code:

Dim comp As Object

Try
    While True
        comp = ThisApplication.CommandManager.Pick(
            SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, 
            "Select a component") 
        oTagOcc = InputBox("Enter Tag No: ", "Tag Prompt", comp.Name)
            comp.Name = oTagOcc
    End While
Catch ' do nothing if error
MessageBox.Show("Tag exists or user canceled", "iLogic")


End Try

END EDIT:

ADS.