Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Guide: How to get AutoCAD Electrical TAGs into Inventor Drawing

7 REPLIES 7
Reply
Message 1 of 8
Colbjørn
698 Views, 7 Replies

Guide: How to get AutoCAD Electrical TAGs into Inventor Drawing

Hi.

 

A lot of credits to the guy that made this guide:

http://blog.ads-sol.com/2014/08/component-tags-in-inventor.html?m=1

 

I have a Mechanical Link set up for my assembly and I want to show the TAG's from AutoCAD Electrical schematics in the Inventor drawing.

So I have modified the code from the guide above to get the Electrical TAG's via the Mechanical Linked assembly.

 

SyntaxEditor Code Snippet

Sub Main()
    test(ThisApplication)
End Sub

 Private Sub test(ByVal app As Inventor.Application)
    Dim oDrawDoc As DrawingDocument = app.ActiveDocument
    Dim oSheet As Sheet = oDrawDoc.ActiveSheet
    Dim oBalloon As Balloon
    
    For Each oSheets In oDrawDoc.Sheets
        For Each oBalloon In oSheet.Balloons
            Dim oLeader As Leader = oBalloon.Leader
            Dim oLeaderNode As LeaderNode = oLeader.AllNodes(2)
            Dim oGeometryIntent As GeometryIntent = oLeaderNode.AttachedEntity
            Dim oDrawingCurve As DrawingCurve = oGeometryIntent.Geometry
            Dim oModelGeom As Object = oDrawingCurve.ModelGeometry
            Dim oComponentOccurrence As ComponentOccurrence = oModelGeom.ContainingOccurrence
            Dim attrbSets = oComponentOccurrence.AttributeSets
            Dim attrbSet = attrbSets.Item("com.autodesk.mechatronics")
            Dim attrib = attrbSet.Item("ComponentTag")
            Dim oBalloonValueSet As BalloonValueSet
    
            If oBalloon.Style.Name = "Tags" Then
                For Each oBalloonValueSet In oBalloon.BalloonValueSets
                    oBalloonValueSet.OverrideValue = attrib.Value
                    Exit For
                Next
            End If
        Next
    Next
End Sub

 

Colbjørn.

7 REPLIES 7
Message 2 of 8
salariua
in reply to: Colbjørn

@Colbjørn

 

the guy who made the guide salutes you. What a nice job you've done..... keep up the good work.

 

I wish the AutoCAD P&ID could be linked.

 

:((

Adrian S.
blog.ads-sol.com 

AIP2012-2020 i7 6700k AMD R9 370
Did you find this reply helpful ?
If so please use the Accepted Solutions or Like button - Thank you!
Message 3 of 8
Colbjørn
in reply to: Colbjørn

Updated code:

  • Multi-Level Assembly Structure supported
    (Both top level assembly and sub assembly has to be connected to the mechanical link.)
  • Multi-Page Drawing document supported
  • Leaders with multiple nodes supported
  • Error Handling with feed back to balloon text

 

 SyntaxEditor Code Snippet

Sub Main()
    UpdateBalloonTAG()
End Sub

Private Sub UpdateBalloonTAG()
    Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
    Dim oLeader As Leader
    Dim oLeaderNode As LeaderNode
    Dim oGeometryIntent As GeometryIntent
    Dim oDrawingCurve As DrawingCurve
    Dim oModelGeom As Object
    Dim oComponentOccurrence As ComponentOccurrence
    Dim oParentDefinition As ComponentDefinition
    Dim oAttributeSets as AttributeSets
    Dim oAttributeSet As AttributeSet
    Dim oBalloonString As String
    Dim intStart As Integer
    Dim intStop As Integer
    Dim oBalloonValueSet As BalloonValueSet
    
    
    For Each oSheet In oDrawDoc.Sheets
        For Each oBalloon In oSheet.Balloons
            If Not oBalloon.Style.Name = "Balloon TAG" Then Continue For 
                oLeader = oBalloon.Leader
                oLeaderNode = oLeader.AllNodes(oLeader.AllNodes.Count)
                oGeometryIntent = oLeaderNode.AttachedEntity
                oDrawingCurve = oGeometryIntent.Geometry
                oModelGeom = oDrawingCurve.ModelGeometry
                oComponentOccurrence = oModelGeom.ContainingOccurrence
                oAttributeSets = oComponentOccurrence.AttributeSets
                
                On Error Resume Next
                oAttributeSet = oAttributeSets.Item("com.autodesk.mechatronics")

                If Err.Number <> 0 Then
                    Err.Clear
                    
                    If oComponentOccurrence.ParentOccurrence.Name = "" Then
                        oBalloon.BalloonValueSets.Item(1).OverrideValue = "FAILED!"
                        Continue For
                    Else
                        oParentDefinition = oComponentOccurrence.ParentOccurrence.Definition
                        oAttributeSets = oParentDefinition.Occurrences.ItemByName(oComponentOccurrence.Name).AttributeSets

                    On Error Resume Next
                    oAttributeSet = oAttributeSets.Item("com.autodesk.mechatronics")            
                    
                    If Err.Number <> 0 Then
                        Err.Clear
                        oBalloon.BalloonValueSets.Item(1).OverrideValue = "FAILED!"
                        Continue For
                    End If
                End If
            End If
            
            If oAttributeSet.Item("Category").Value = "TRMS" Then
                intStart = InStr(1, oAttributeSet.Item("TerminalBlock").Value, "TerminalBlockNumber", CompareMethod.Text) + 21
                intStop = InStr(1, oAttributeSet.Item("TerminalBlock").Value, "TerminalBlockPinL", CompareMethod.Text) - 2
                oBalloonString = oAttributeSet.Item("TerminalStripTag").Value & ":" & Mid(oAttributeSet.Item("TerminalBlock").Value, intStart ,intStop - intStart)
            Else
                oBalloonString = oAttributeSet.Item("ComponentTag").Value
            End If
            
            For Each oBalloonValueSet In oBalloon.BalloonValueSets
                oBalloonValueSet.OverrideValue = oBalloonString
                Exit For
            Next
        Next
    Next
End Sub

 

 

 

Message 4 of 8
Colbjørn
in reply to: Colbjørn

Updated Code:

  • Multi-Level Assembly Structure supported
    (Both top level assembly and sub assembly has to be connected to the mechanical link.)
  • Array in sub-assembly with electrical components 
  • Multi-Page Drawing document supported
  • Leaders with multiple nodes supported
  • Error Handling with feed back to balloon text 

 SyntaxEditor Code Snippet

Sub Main()
    UpdateBalloonTAG()
End Sub

Private Sub UpdateBalloonTAG()
    Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
    Dim oLeader As Leader
    Dim oLeaderNode As LeaderNode
    Dim oGeometryIntent As GeometryIntent
    Dim oDrawingCurve As DrawingCurve
    Dim oModelGeom As Object
    Dim oComponentOccurrence As ComponentOccurrence
    Dim oParentDefinition As ComponentDefinition
    Dim oAttributeSets as AttributeSets
    Dim oAttributeSet As AttributeSet
    Dim oBalloonString As String
    Dim intStart As Integer
    Dim intStop As Integer
    Dim oBalloonValueSet As BalloonValueSet
    
    
    For Each oSheet In oDrawDoc.Sheets
        For Each oBalloon In oSheet.Balloons
            If Not oBalloon.Style.Name = "Balloon TAG" Then Continue For 
                oLeader = oBalloon.Leader
                oLeaderNode = oLeader.AllNodes(oLeader.AllNodes.Count)
                oGeometryIntent = oLeaderNode.AttachedEntity
                oDrawingCurve = oGeometryIntent.Geometry
                oModelGeom = oDrawingCurve.ModelGeometry
                oComponentOccurrence = oModelGeom.ContainingOccurrence
                oAttributeSets = oComponentOccurrence.AttributeSets
                
                On Error Resume Next
                oAttributeSet = oAttributeSets.Item("com.autodesk.mechatronics")

                If Err.Number <> 0 Or Not oComponentOccurrence.ParentOccurrence.Name = "" Then
                    Err.Clear
                    
                    If oComponentOccurrence.ParentOccurrence.Name = "" Then
                        oBalloon.BalloonValueSets.Item(1).OverrideValue = "FAILED!"
                        Continue For
                    Else
                        oParentDefinition = oComponentOccurrence.ParentOccurrence.Definition
                        oAttributeSets = oParentDefinition.Occurrences.ItemByName(oComponentOccurrence.Name).AttributeSets

                    On Error Resume Next
                    oAttributeSet = oAttributeSets.Item("com.autodesk.mechatronics")            
                    
                    If Err.Number <> 0 Then
                        Err.Clear
                        oBalloon.BalloonValueSets.Item(1).OverrideValue = "FAILED!"
                        Continue For
                    End If
                End If
            End If
            
            If oAttributeSet.Item("Category").Value = "TRMS" Then
                intStart = InStr(1, oAttributeSet.Item("TerminalBlock").Value, "TerminalBlockNumber", CompareMethod.Text) + 21
                intStop = InStr(1, oAttributeSet.Item("TerminalBlock").Value, "TerminalBlockPinL", CompareMethod.Text) - 2
                oBalloonString = oAttributeSet.Item("TerminalStripTag").Value & ":" & Mid(oAttributeSet.Item("TerminalBlock").Value, intStart ,intStop - intStart)
            Else
                oBalloonString = oAttributeSet.Item("ComponentTag").Value
            End If
            
            For Each oBalloonValueSet In oBalloon.BalloonValueSets
                oBalloonValueSet.OverrideValue = oBalloonString
                Exit For
            Next
        Next
    Next
End Sub

 

 

Message 5 of 8
m.hamiltonYPSAS
in reply to: Colbjørn

Is there a way to do this, but not use balloon tags...?   instead import the Tag Data into text that could be used to make an engraved label that would come into a bill of materials as a part?  

 

The name of the component exists in ACADE and also exists in the link file...   maybe make a balloon that looks like a phenolic label?  

 

This seems such a simple question but I cant figure it out. 

 

In AutoCAD Electrical I have Circuit Breaker 150 "CB-150" and I just want that text to show as a Nameplate / Tag in Inventor. 

Message 6 of 8
PaulMunford
in reply to: salariua

@salariua Will Instance properties in Inventor 2022 streamline this process at all?

 


Autodesk Industry Marketing Manager UK D&M
Opinions are my own and may not reflect those of my company.
Linkedin Twitter Instagram Facebook Pinterest

Message 7 of 8
salariua
in reply to: PaulMunford

Hi @PaulMunford .

 

I have no idea about 2022 and Instance Properties.

As any major corporation in the world mine is couple versions back, still on AIP 2019 🙂

 

 

Adrian S.
blog.ads-sol.com 

AIP2012-2020 i7 6700k AMD R9 370
Did you find this reply helpful ?
If so please use the Accepted Solutions or Like button - Thank you!
Message 8 of 8
PaulMunford
in reply to: salariua

I'll look forward to hearing your feedback once you get caught up 😉

 


Autodesk Industry Marketing Manager UK D&M
Opinions are my own and may not reflect those of my company.
Linkedin Twitter Instagram Facebook Pinterest

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report