Showing posts with label tag. Show all posts
Showing posts with label tag. Show all posts

Thursday, 4 September 2014

Numeric Increment for AutoCAD

Another post on incrementing tags for valves, equipment and instrumentation on P&I D done with AutoCAD.
I hate repetitive boring jobs so I much rather spend a couple of hours researching for a quicker, faster solution before doing the mundane.
In this case I wanted to automate the assignment and incrementing of tags numbers for valves, instrumentation and general texts in electric schematics.


So after a bit of research I came across Lee-Mac's website. This site is full of goodies and for my problem I stopped at "Incremental Numbering Suite".
You really need to open the webpage to see the full capabilities of this routine but here’s how I've used it.
Fits, I've selected all my instrumentation and added “000” to the tag number so that the function can pick it up as a number that needs changing (incrementing).
Type numinc to get the options window.
We start all instrumentation at 500 so I have 501 for my fist number with 1 as increment. You can type it anywhere in the prefix, middle or suffix as long as you tick the correct section to increment bellow.


I have then clicked the “pick on screen” to select the block type that needs changing, selected my block and clicked OK.



At the command prompt type “R” in order to replace an existing value, in my case “000”. Click on each object that you want modified in the exact order you want it incremented.


I have placed a temporary valve tagging block and started the numinc again. I have used “V” as prefix and 101 (we start all valve tags at 100) as middle incrementing middle by 1 each time. Select the temporary valve block with “pick on screen” for objects to modify and click “OK”.



I haven’t used “R” because I need the program to place new blocks on the fly just like in the image bellow. 

Totally love Lee Mac’s website and if you find it useful, it won’t hurt to donate especially since he keeps his source code free. It's nice to see the code that does all this magic.

ADS

Thursday, 14 August 2014

Component Tags in Inventor

As you are aware if you have done any routed systems there is no way of labeling same valve (or components for that matter) with different names / tags / id_numbers and call it on the drawing. You can create leader notes in the drawing but if they need changing you need to manually do it and it’s time consuming if you have large assemblies and multiple sheets and views. I have seen the same problem for people doing assemblies of electric components.
A 2” ball valve can have different identification tags in the P&ID but be a reused library component in Inventor.

I've been searching for a solution to this problem for the last 8 years or so and I couldn't find anything on autodesk forums or other discussion groups.
I instinctively knew that we would need to use the assembly browser name (occurrence name) but didn't see how to get it to show up in the drawing.

I have got together bits of iLogic codes from the internet that can get the assembly occurrence name and link it to the override value of my custom style balloons.
For this I have created a new balloon style called “Tags” and made it of type “Hexagon” with just the “Item” info in it.

The code processes just balloons of style “Tags” for we don’t want to change parts list balloons as well.
Because changing the occurrence name in the assembly involves a lot of steps (find component in browser / edit parent subassembly / change name of component / activate top level again) it is better to do it from the drawing.
You need to use “balloon” command, because “auto-balloon” cannot label same component on different views more than once.

Place balloons as you would normally do using “balloon” command and override the field with your text. You only need to do it once per component then run the code

When running the code it will prompt you if you want to set names from the balloons or from the browser. Choose balloon to send the override value to the model browser (occurrence name).

Continue placing balloons on all views and then run the code again. Choose to set the value from the browser to get the value on all new balloons.

This way I can balloon same component multiple times on same view if wanted.

As you can see the Occurrence name in browser and iproperties changed but the part number, stock number and other properties didn't changed.


Here's the code with explanatory comments:

' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

' Set Reference to Active Sheet
Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet

'get the name and path of the first model in the drawing
oAsmName = ThisDrawing.ModelDocument.FullFileName

' Set Reference to the Assembly and Open Silently
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.Documents.Open(oAsmName, False)

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

Dim oBalloon As Balloon

'Ask the user if he wants to set the component name from browser
'or if he wants to set the browser name from overwritten balloon value
booleanParam = InputRadioBox("Set name from?: ", "Browser", "Balloon", True, Title :="Read/Write")


'Start a counter for sheets to process
Dim SheetCount As Long
SheetCount = 1
Dim oSheets As Sheet
'step through each drawing sheet
For Each oSheets In oDrawDoc.Sheets

    ' Iterate over each balloon on the sheet.
    For Each oBalloon In oSheet.Balloons
        Dim leader As Leader
        Leader = oBalloon.Leader
        'assuming the leader is a single line segment
        Dim leaderNode As LeaderNode = leader.AllNodes(2)
       
        Dim intent As GeometryIntent
        intent = leaderNode.AttachedEntity
   
        Dim curve As DrawingCurve
        curve = intent.Geometry
   
        Dim edgePx As EdgeProxy
        edgePx= curve.ModelGeometry
   
        Dim occurrencedrg As ComponentOccurrence
        occurrencedrg = edgePx.ContainingOccurrence
        
        Dim oBalloonValueSet As BalloonValueSet
       
        ' Iterate over each value set (attached balloons) in a balloon.
        For Each oBalloonValueSet In oBalloon.BalloonValueSets
            'only process if balloon of style of type "Tags"
            If oBalloon.Style.Name = "Tags" Then
                'if user wants to get name from browser
                If booleanParam = True Then
                    ' Set balloon value from browser.
                    oBalloonValueSet.OverrideValue = occurrencedrg.Name
                'if user wants to set browser name from balloon
                ElseIf booleanParam = False Then
                    ' Set browser name from balloon override value.
                    occurrencedrg.Name = oBalloonValueSet.OverrideValue
                End If
            End If
        Next
    Next
'Increase sheet counter
    SheetCount = SheetCount +1
Next



Best of  luck

ADS.