I have been toying with getting
certain information from the models to the drawing and set it up neatly in a
table.
Unfortunately
getting it in a General table is not possible but adding that info into a Parts
List table is.
At this
point I need to mention that my table has no Parts in it (I use part list on
single model not assembly) but rather a collection of parameters and,
properties, found on the model. You can virtually add any info from the model
to the drawing and show it on a neat table rather than using leader texts.
A
couple of examples of what you can get (what I can think of at the moment):
-
Sheet metal flat size
-
Model size
-
Any parameter (like volume) or iProperties from
the model (user custom iProperties or not)
-
Color of the model
-
Suppressed and available features
-
Surface area of model (for painting and coating
calcs) (need a bit of ilogic first to calculate area)
-
Etc.
What I needed
was to get a list of active tank connections, size, type, position angle and
description from the model as in the image bellow:
A typical code
that looks for a part number and then writes to the description column of that
row if the part number matches would be (Kudos to Curtis Waguespack):
' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
' Set a reference to the first parts list on the active
sheet.
' This assumes that a parts list is on the active sheet.
Dim oPartList As PartsList
oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
' Iterate through the contents of the parts list.
Dim i As Long
For i = 1 To oPartList.PartsListRows.Count
'look at only the part number column
oCell =
oPartList.PartsListRows.Item(i).Item("PART NUMBER")
'find
a specific part number
If
oCell.Value = "12-345" Then
'identify
the cell in the description column for the row that
'the
part number was found in
oCell2
= oPartList.PartsListRows.Item(i).Item("DESCRIPTION")
'write
to the target cell
oCell2.Value
= "Bingo!"
End
if
Next
Now you
can play with:
-
If part number matches or contains....
-
If description or any other properties matches
or contains....
-
If model is in a certain folder or location on
disk (kind of tell if its library)
-
If weight over xx...
-
Whatever you can think off..
and add a certain text or value
to cell of the table like image bellow:
So first add a parts list (even
if you have just a part on the model).
Edit the part list, click Column
Chooser, User Properties. Add New Property and type all the properties you want
to have in the table.
Take off visibility of the part
in the table. If you right click on the model row you have the option to “Insert
Custom Part” or “Remove Custom Part” and that’s what we’ll use in our ilogic
code to get our info to show up.
Add a new rule in the Ilogic code
browser.
Hope the comments on the code are
self-explanatory:
' Set a reference to the drawing
document.
' This assumes a drawing document is
active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
'get the name of the first model in the
drawing
modelName = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)
' Set a reference to the first parts
list on the active sheet
' This assumes that a parts list is on
the active sheet.
Dim oPartList As PartsList
oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
'count existing nr of rowsin the table
oCountRow = oPartList.PartsListRows.Count
At
this point it was easier to delete the current table and write the info again because
the number of connections on the model can increase decrease an I didn't wanted
to start playing with count, compare, delete, add. etc.
You can only add and
remove Custom Parts from the table so the "count existing rows to process" needs to be -1 that can't be deleted.
'remove the current rows
Dim i As Long
For i = 1 To oCountRow - 1 ' can't delete last row that is not
custom part
oPartList.PartsListRows.Item(1).Remove() 'remove
the first row al the time so you don't get error when removing row (i) say:4 on
a 3 row table
Next
You
need to keep track of the number of rows you are writing in separately because
the model can have 30 connections total but only 5 unsequenced connections active.
Connection 30 in the model will not appear as N30 on the drawing but rather the
next available sequenced number so we will use the row count in the first cell as
well.
'Start at first row of the table and
keep track of added rows
Dim row As Integer
row = 1
'Add the values we need
'Loop trough the nr of instances we need
to add
For i = 1 To 25 '25
max tank connections at the moment
'set
oMyPar as the current N i connection
oMyPar = Parameter(modelName, "N" & i & "_Conn")
'don't
throw error if the parameter is not created yet (does not exist)
Parameter.Quiet=True
'check
if the parameter is set to true - Connection N(i) is used in the model
If oMyPar = True Then
'add
another custom row to the table with options (position at index row, before
index true)
'to
add Custom parts before the actual model part set as not visible In
table
oPartList.PartsListRows.Add(row, True)
Instead
of using Item(“Column name here”) you can use a number to indicate the column number like Item(1).
oCell_Item = oPartList.PartsListRows.Item(row).Item("Item")
This
is where we add the connection number based on the current row number rather
than getting it from the model (not sequential).
oCell_Item.Value = "N" & row
oCell_Size = oPartList.PartsListRows.Item(row).Item("Size")
oCell_Size.Value = Parameter(modelName, "N" & i & "_Size")
oCell_Type = oPartList.PartsListRows.Item(row).Item("Type")
oCell_Type.Value = Parameter(modelName, "N" & i & "_Type")
oCell_Ang = oPartList.PartsListRows.Item(row).Item("Angle")
oCell_Ang.Value = Parameter(modelName, "N" & i & "_Angle")
oCell_Desc = oPartList.PartsListRows.Item(row).Item("Description")
oCell_Desc.Value = Parameter(modelName, "N" & i & "_Desc")
'increase
row number for next loop
row = row + 1
End If
Next
Again,
I am not a programmer myself, and I just gathered this of the internet and got
it customised for my case. I hope I have at least guided you in the right
direction, and not confused you more.
Here is
the code again without my comments all over.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
modelName = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)
Dim oPartList As PartsList
oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
oCountRow = oPartList.PartsListRows.Count
Dim i As Long
For i = 1 To oCountRow - 1
oPartList.PartsListRows.Item(1).Remove
Next
Dim row As Integer
row = 1
For i = 1 To 25
oMyPar = Parameter(modelName, "N" & i & "_Conn")
Parameter.Quiet=True
If oMyPar = True Then
oPartList.PartsListRows.Add(row, True)
oCell_Item = oPartList.PartsListRows.Item(row).Item("Item")
oCell_Item.Value = "N" & row
oCell_Size = oPartList.PartsListRows.Item(row).Item("Size")
oCell_Size.Value = Parameter(modelName, "N" & i & "_Size")
oCell_Type = oPartList.PartsListRows.Item(row).Item("Type")
oCell_Type.Value = Parameter(modelName, "N" & i & "_Type")
oCell_Ang = oPartList.PartsListRows.Item(row).Item("Angle")
oCell_Ang.Value = Parameter(modelName, "N" & i & "_Angle")
oCell_Desc = oPartList.PartsListRows.Item(row).Item("Description")
oCell_Desc.Value = Parameter(modelName, "N" & i & "_Desc")
row = row + 1
End If
Next
No comments:
Post a Comment