Drawing View/Parts List Mass Label Text

Drawing View/Parts List Mass Label Text

Jason.Rugg
Collaborator Collaborator
1,625 Views
21 Replies
Message 1 of 22

Drawing View/Parts List Mass Label Text

Jason.Rugg
Collaborator
Collaborator

@Anonymous or anyone, looking for a way to streamline our process of adding weights to drawing parts lists. At the bottom of every parts list on a drawing we manually add a text box that references a custom user parameter/rule (MKMASS) in the assembly model that automatically updates when the model changes. Is there a way to make this TOTAL WT... text part of the parts list and automatically gets the weight from the referenced parts list model? Or is there a way to still have the text separate but be able to select a view or the parts list and it automatically drop in the weight text box already formatted as shown below?

 mass.png mass 2.png

0 Likes
Accepted solutions (1)
1,626 Views
21 Replies
Replies (21)
Message 2 of 22

WCrihfield
Mentor
Mentor

Hi @Jason.Rugg.  I don't believe it can actually be added as part of the PartsList itself.  You may be able to incorporate a special column for per row weight, but likely not a total assembly weight unless another unique row is used that simply has that same data in each row.  The good news is that I believe it can be done separately from the PartsList though.  But it will likely be a pain to code, because the TextBox.FormattedText will need to include special pieces of XML code to make the 'live link' type behavior work.  Here is a link to a related online help page, but it isn't really that helpful.  Then being able to place the textbox specifically where you want it will likely be less of a challenge, but will require some input about your preferences.  Then there is the option of whether you want the code to attempt to find this TextBox, to see if it already exists, before attempting to possibly re-create it.  If that may be an issue, it can likely be dealt with by code, but will add a bit to its complexity, because TextBox's don't have a Name.  If your PartsList is always at the top of your sheet?  Is it always at the right side of the sheet?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 22

Jason.Rugg
Collaborator
Collaborator

@WCrihfield It does not need to be part of the part list itself, I didn't figure that would be an easy thing to do if it was even possible. As far as placement of the text box goes, that's not super important maybe nice if it would always place it where it needs to go but as long as it can at least place it somewhere on the drawing it is easy enough to drag into place. Parts list always start at the top right hand corner of the drawing and if multiple are added they are placed below but if we run out of room (which isn't often) we start placing them along the top of the drawing to the left of the initial one. I also don't think the code needs to search for an existing text box, it can place a new one every time, its easy enough to delete old ones but if the weight gets updated automatically there really shouldn't be a reason to recreate that specific text box.

0 Likes
Message 4 of 22

WCrihfield
Mentor
Mentor

Leaving for the day, but try this rule, and see if it works for you.

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("A Drawing Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.", vbCritical, "iLogic")
	Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
oSheet = oDDoc.ActiveSheet
oPick = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingPartsListFilter, "Select a Parts List for Document Reference.")
If IsNothing(oPick) OrElse (Not TypeOf oPick Is PartsList) Then Exit Sub
Dim oPList As PartsList = oPick
Dim oRefDoc As Document = oPList.ReferencedDocumentDescriptor.ReferencedDocument
oFFN = oRefDoc.FullFileName
oParamName = "MKMASS"
oParamNote = "<Parameter ComponentIdentifier='" & oFFN & "' Name='" & oParamName &"' Precision='1' ></Parameter>"
oFText = "TOTAL WT/MK:  " & oParamNote & " LBS"
oPosition = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)
oGenNote = oSheet.DrawingNotes.GeneralNotes.AddFitted(oPosition, oFText)

I'll check back tomorrow.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 22

JelteDeJong
Mentor
Mentor

I wonder why you don't add this information to your title block. I would think that the 2e best option is what @WCrihfield suggest. What I'm going to suggest here is not what I personally would do but it is an option. 

It's possible to add an extra row to a parts list and populate the cells with information that you can provide yourself. here I populated the 3th cell with a description text ("TOTAL WT/MK"), and the 4th cell with the mass.

Dim doc As DrawingDocument = ThisDoc.Document
Dim sheet As Sheet = doc.ActiveSheet
Dim partsList As PartsList = sheet.PartsLists.Item(1)
Dim newRow As PartsListRow = partsList.PartsListRows.Add(partsList.PartsListRows.Count, False)
For Each cell As PartsListCell In newRow
    Cell.Value = ""
Next
Dim descriptionCell As PartsListCell = newRow.Item(3)
Dim valueCell As PartsListCell = newRow.Item(4)

descriptionCell.Value = "TOTAL WT/MK"

Dim refdoc As Document = partsList.ReferencedDocumentDescriptor.ReferencedDocument
Dim mass As Double = refdoc.ComponentDefinition.MassProperties.Mass

valueCell.Value = Math.Round(mass, 1) & "Kg"

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 6 of 22

Jason.Rugg
Collaborator
Collaborator

@WCrihfield Wow, that is definitely a lot less coding than I ever thought it would be. So I copied and pasted your rule into "rule1" in a test drawing, I am able to select a parts list and then it returns the following error: 

 

Error in rule: Rule1, in document: 84480320.dwg

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
Message 7 of 22

Jason.Rugg
Collaborator
Collaborator

@JelteDeJong Adding the info to the titleblock isn't really an option for us because of the way our drawings are formatted and the use of client titleblocks and multiple parts lists on a drawing. I will definitely try out your rule though and see if that is an option we could consider. 

0 Likes
Message 8 of 22

Jason.Rugg
Collaborator
Collaborator

@JelteDeJong I actually do kind of like where this is going, however, I would want the option to run this on multiple parts lists on the drawing. Currently it only works for the first parts list that was added to the drawing. Below is a screenshot of a sample parts list manually added rows that your rule would create.

 

After the last item row I would want a blank row inserted and then the next row have the weight information. Ideally I would want the TOTAL WT/MK: text to be inserted into the WT EA column but because of the way our parts lists are setup that cell automatically changes to "Incompatible Units Error" so the next best place for that text I think would be under the DESCRIPTION column.

 

Also, what in your code is specifying the mass units? I would want this to be in pounds but couldn't figure out what was controlling that.

 

I think the only reason this approach may not work is because of the custom program called BOM Manager that we process drawings through. It is setup to automatically extract information from the drawing parts lists, I am having conversations with the creator of that program to see if we can get it to exclude these extra weight rows that the rule is inserting.

 

mass 3.png

0 Likes
Message 9 of 22

JelteDeJong
Mentor
Mentor

I changed the rule a bit.

You can select a parts list that you want to update.

An empty row is also added.

Internally Inventor always uses Kg for mass. if you want some other units you need to convert them yourself.  This is also done in the new rule.

You could ask if the "BOM Manager" can skip rows if, for example, the "Item" cell is empty.

Dim doc As DrawingDocument = ThisDoc.Document
Dim sheet As Sheet = doc.ActiveSheet
Dim partsList As PartsList = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingPartsListFilter, "Select a Parts List for Document Reference.")

Dim newRow As PartsListRow = partsList.PartsListRows.Add(partsList.PartsListRows.Count, False)
For Each cell As PartsListCell In newRow
    Cell.Value = ""
Next

newRow = partsList.PartsListRows.Add(partsList.PartsListRows.Count, False)
For Each cell As PartsListCell In newRow
    Cell.Value = ""
Next

Dim descriptionCell As PartsListCell = newRow.Item(3)
Dim valueCell As PartsListCell = newRow.Item(4)

descriptionCell.Value = "TOTAL WT/MK"
Dim refdoc As Document = partsList.ReferencedDocumentDescriptor.ReferencedDocument
Dim mass As Double = refdoc.ComponentDefinition.MassProperties.Mass
mass = mass / 0.45359237
valueCell.Value = Math.Round(mass, 1) & "Lb"

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 10 of 22

Jason.Rugg
Collaborator
Collaborator

I like this, now it's just a matter of if our BOM MANAGER program will play nice with it. I am sure the answer to this is no but is it possible for the weight to be updated automatically if the model changes instead of running the rule again? 

0 Likes
Message 11 of 22

Jason.Rugg
Collaborator
Collaborator

@JelteDeJong This works great, is there a way though to get the weight to automatically update if the weight changes without having to delete the two rows and running the rule again?

0 Likes
Message 12 of 22

Jason.Rugg
Collaborator
Collaborator

@JelteDeJong I have been thinking about the auto update, could we have separate rule that could be run that could force an update of the total weight number inside of the parts list?

0 Likes
Message 13 of 22

JelteDeJong
Mentor
Mentor

this rule will check the last row for the description text. if its found it will update the value.

 

Dim doc As DrawingDocument = ThisDoc.Document
For Each sheet As Sheet In doc.Sheets
    For Each partsList As PartsList In Sheet.PartsLists
        Dim lastRow As PartsListRow = PartsList.PartsListRows.Item(PartsList.PartsListRows.Count)
        Dim descriptionCell As PartsListCell = lastRow.Item(3)
        Dim valueCell As PartsListCell = lastRow.Item(4)

        If (descriptionCell.Value = "TOTAL WT/MK") Then
            Dim refdoc As Document = PartsList.ReferencedDocumentDescriptor.ReferencedDocument
            Dim mass As Double = refdoc.ComponentDefinition.MassProperties.Mass
            mass = mass / 0.45359237
            valueCell.Value = Math.Round(mass, 1) & "Lb"
        End If

    Next
Next

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 14 of 22

Jason.Rugg
Collaborator
Collaborator

I feel we are very close, when I run the second update rule, it doesn't update my text but it doesn't error out either. Here are my two rules, I changed them slightly from the originals but not seeing why it's not working.

 

Dim doc As DrawingDocument = ThisDoc.Document
Dim sheet As Sheet = doc.ActiveSheet
Dim partsList As PartsList = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingPartsListFilter, "Select a Parts List for Weight Calculation.")

Dim newRow As PartsListRow = partsList.PartsListRows.Add(partsList.PartsListRows.Count, False)
For Each cell As PartsListCell In newRow
    Cell.Value = ""
Next

newRow = partsList.PartsListRows.Add(partsList.PartsListRows.Count, False)
For Each cell As PartsListCell In newRow
    Cell.Value = ""
Next

Dim descriptionCell As PartsListCell = newRow.Item(5)
Dim valueCell As PartsListCell = newRow.Item(5)

descriptionCell.Value = "TOTAL WT:  "
Dim refdoc As Document = partsList.ReferencedDocumentDescriptor.ReferencedDocument
Dim mass As Double = refdoc.ComponentDefinition.MassProperties.Mass
mass = mass / 0.45359237
valueCell.Value = "TOTAL WT:  " & Math.Round(mass, 1) & " LBS EA."





Dim doc As DrawingDocument = ThisDoc.Document
For Each sheet As Sheet In doc.Sheets
    For Each partsList As PartsList In Sheet.PartsLists
        Dim lastRow As PartsListRow = PartsList.PartsListRows.Item(PartsList.PartsListRows.Count)
        Dim descriptionCell As PartsListCell = lastRow.Item(5)
        Dim valueCell As PartsListCell = lastRow.Item(5)

        If (descriptionCell.Value = "TOTAL WT:  ") Then
            Dim refdoc As Document = PartsList.ReferencedDocumentDescriptor.ReferencedDocument
            Dim mass As Double = refdoc.ComponentDefinition.MassProperties.Mass
            mass = mass / 0.45359237
            valueCell.Value = "TOTAL WT  :  " & Math.Round(mass, 1) & " LBS EA."
        End If

    Next
Next



0 Likes
Message 15 of 22

JelteDeJong
Mentor
Mentor

try the rule like this:

Dim doc As DrawingDocument = ThisDoc.Document
For Each sheet As Sheet In doc.Sheets
    For Each partsList As PartsList In sheet.PartsLists
        Dim lastRow As PartsListRow = partsList.PartsListRows.Item(partsList.PartsListRows.Count)
        Dim descriptionCell As PartsListCell = lastRow.Item(5)
        Dim valueCell As PartsListCell = lastRow.Item(5)

        If (descriptionCell.Value.Contains("TOTAL WT:  ")) Then
            Dim refdoc As Document = partsList.ReferencedDocumentDescriptor.ReferencedDocument
            Dim mass As Double = refdoc.ComponentDefinition.MassProperties.Mass
            mass = mass / 0.45359237
            valueCell.Value = "TOTAL WT  :  " & Math.Round(mass, 1) & " LBS EA."
        End If

    Next
Next

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 16 of 22

Jason.Rugg
Collaborator
Collaborator

That did it, thank you very much, was the only thing you changed the uppercase P to lowercase p on partslist?

0 Likes
Message 17 of 22

JelteDeJong
Mentor
Mentor
Accepted solution

JelteDeJong_0-1637180131373.png

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 18 of 22

Jason.Rugg
Collaborator
Collaborator

@JelteDeJong @WCrihfield Some of my users don't like selecting the parts list and would rather run the rule and it process the weight for every parts list on the drawing at the same time. Thought this would be easy enough by commenting out the third line of code as shown below but apparently not. What do I change or add to make this work?

 

Dim doc As DrawingDocument = ThisDoc.Document
Dim sheet As Sheet = doc.ActiveSheet
'Dim partsList As PartsList = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingPartsListFilter, "Select a Parts List for Weight Calculation.")

Dim newRow As PartsListRow = PartsList.PartsListRows.Add(PartsList.PartsListRows.Count, False)
For Each cell As PartsListCell In newRow
    Cell.Value = ""
Next

 

0 Likes
Message 19 of 22

WCrihfield
Mentor
Mentor

Just pulling the code from your last post, then slightly editing it to remove Pick method, then create a loop of the parts lists on the sheet.  Then put the rest of your code within that loop.  See if that works for you.

Dim doc As DrawingDocument = ThisDoc.Document
Dim sheet As Sheet = doc.ActiveSheet
For Each PartsList As PartsList In sheet.PartsLists
	Dim newRow As PartsListRow = PartsList.PartsListRows.Add(PartsList.PartsListRows.Count, False)
	For Each cell As PartsListCell In newRow
	    Cell.Value = ""
	Next

	newRow = PartsList.PartsListRows.Add(PartsList.PartsListRows.Count, False)
	For Each cell As PartsListCell In newRow
	    Cell.Value = ""
	Next

	Dim descriptionCell As PartsListCell = newRow.Item(5)
	Dim valueCell As PartsListCell = newRow.Item(5)

	descriptionCell.Value = "TOTAL WT:  "
	Dim refdoc As Document = PartsList.ReferencedDocumentDescriptor.ReferencedDocument
	Dim mass As Double = refdoc.ComponentDefinition.MassProperties.Mass
	mass = mass / 0.45359237
	valueCell.Value = "TOTAL WT:  " & Math.Round(mass, 1) & " LBS EA."
Next

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 20 of 22

WCrihfield
Mentor
Mentor

Wait a second there...You had both your Description cell and your Value cell pointing to cell 5.  I'm sure one of those should be the next number, or at least different, or maybe even just eliminate one of them, if you are planning on putting it all into one cell?  But I will leave that to you, because you know your parts lists better than I do.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes