This has got me stumped. I am trying to rewrite Curtis Waguespack's ilogic code to modify drawing view labels from this post http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/Custom-user-properties-in-view-label-o...
The completed label should appear like this
<Description> - Mk <Part Number>
Est Unit Mass = X kg
(Scale 1:1)
At this point I have 2 problems
1. I want to add the physical mass to the second line and would prefer to use the calculated physcial property rather than the a custom iproperty. If editing the view label, it would the property access under physcial properties.
2. I want to rewrite the code so it is selective or per view - in otherwords, I only want it to modify a single view I select once the code is run. At this point I know I need to remove the For loop but I dont have a clue as to how to make it selective.
So far this is what I have, any help would be much appreciated
Steve
'start of ilogic codeDim oDoc As DrawingDocument: oDoc = ThisDoc.Document oModel = ThisDoc.ModelDocument Dim oSheets As Sheets Dim oSheet As Sheet Dim oViews As DrawingViews Dim oView As DrawingView oSheets = oDoc.Sheets For Each oSheet In oSheets oViews = oSheet.DrawingViews For Each oView In oViews oView.ShowLabel = True Try 'format the model iproperties oDescription = "<StyleOverride Underline='True'><Property Document='model' PropertySet='Design Tracking Properties' Property='Description' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='29'>DESCRIPTION</Property></StyleOverride>" oPartNumber = "<StyleOverride Underline='True'> - Mk <Property Document='model' PropertySet='Design Tracking Properties' Property='Part Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>PART NUMBER</Property></StyleOverride>" 'Dim oMassStr As String = Round(oDoc.ComponentDefinition.MassProperties.Mass,0) 'format the custom iproperty string and add the property ID oStringMass = "<Br/><StyleOverride Underline='False' FontSize='0.35'>EST UNIT MASS = <PhysicalProperty PhysicalPropertyID='72449' Precision='0'>MASS</PhysicalProperty></Property>,</StyleOverride>" 'oStringMass = "<PhysicalProperty PhysicalPropertyID='72449' Precision='0'>MASS</PhysicalProperty></Property>" oStringScale = "<Br/><StyleOverride FontSize='0.3'>(Scale <DrawingViewScale/>)</StyleOverride>" 'add the custom iproperties to the view label 'oView.Label.FormattedText = oDescription & oPartNumber & oStringMass & oStringScale oView.Label.FormattedText = oDescription & oPartNumber & oStringScale Catch 'do nothing if error End Try Next Next 'end of ilogic code
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
This sample rule prints the mass of the model
that is referenced by the first selected drawing view.
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet If oSSet.count = 0 Then MsgBox("Select a drawing view") Exit Sub End If 'Reference to the drawing view from the 1st selected object Dim oView As DrawingView = trycast(osset.item(1), DrawingView) If oView IsNot Nothing Then 'do something with this drawing view Dim oModelDoc as Inventor.Document = ThisDrawing.ModelDocument ' Set a reference to the mass properties object. Dim oMassProps As MassProperties _ = oModelDoc.ComponentDefinition.MassProperties ' Set the accuracy to medium. oMassProps.Accuracy = MassPropertiesAccuracyEnum.k_Low Dim M As Double = oMassProps.Mass MsgBox( "View: " & oview.Name & vbNewLine & _ "Scale = " & oview.Scale.tostring & vbNewLine & _ "Mass, kg = " & FormatNumber(M, 3)) Else MsgBox("Selected object is not a drawing view") End If
Hope this helps.
Thanks Vladimir, your code helped with the selection of the view and setting a static mass value to the view label.
Ideally I still would like the mass value to be dynamic and update if the assembly mass updates. My thoughts are that I would be able to access the view mass propoerty.
Anybody have any ideas on how to do that.
The code as it stands now which requires the user to select the view prior to running
'start of ilogic code Dim oDoc As DrawingDocument: oDoc = ThisDoc.Document oModel = ThisDoc.ModelDocument Dim oSheets As Sheets Dim oSheet As Sheet Dim oViews As DrawingViews 'Dim oView As DrawingView oSheets = oDoc.Sheets Dim oSSet As SelectSet = ThisDoc.Document.SelectSet If oSSet.count = 0 Then MsgBox("Select a drawing view and rerun ilogic code") Exit Sub End If 'Reference to the drawing view from the 1st selected object Dim oView As DrawingView = trycast(osset.item(1), DrawingView) If oView IsNot Nothing Then 'do something with this drawing view Dim oModelDoc as Inventor.Document = ThisDrawing.ModelDocument ' Set a reference to the mass properties object. Dim oMassProps As MassProperties _ = oModelDoc.ComponentDefinition.MassProperties ' Set the accuracy to medium. oMassProps.Accuracy = MassPropertiesAccuracyEnum.k_Low Dim M As Double = oMassProps.Mass 'MsgBox( "View: " & oview.Name & vbNewLine & _ ' "Scale = " & oview.Scale.tostring & vbNewLine & _ ' "Mass, kg = " & FormatNumber(M, 3)) oView.ShowLabel = True 'format the model iproperties oDescription = "<StyleOverride Underline='True'><Property Document='model' PropertySet='Design Tracking Properties' Property='Description' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='29'>DESCRIPTION</Property></StyleOverride>" oPartNumber = "<StyleOverride Underline='True'> - Mk <Property Document='model' PropertySet='Design Tracking Properties' Property='Part Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>PART NUMBER</Property></StyleOverride>" 'format the custom iproperty string and add the property ID oStringMass = "<Br/><StyleOverride Underline='False' FontSize='0.35'>EST UNIT MASS = "& FormatNumber(M, 0)&" kg</StyleOverride>" oStringScale = "<Br/><StyleOverride FontSize='0.3'>(Scale <DrawingViewScale/>)</StyleOverride>" 'add the custom iproperties to the view label oView.Label.FormattedText = oDescription & oPartNumber & oStringMass & oStringScale Else MsgBox("Selected object is not a drawing view") End If 'end of ilogic code
Regards Steve
Hi Slothian,
This should do it:
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet If oSSet.count = 0 Then MessageBox.Show("You must select a drawing view first", "iLogic") Exit Sub End If 'Reference to the drawing view from the 1st selected object Dim oView As DrawingView = trycast(oSSet.item(1), DrawingView) If oView IsNot Nothing Then oView.ShowLabel = True 'format the model iproperties oDescription = "<StyleOverride Underline='True'><Property Document='model' PropertySet='Design Tracking Properties' Property='Description' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='29'>DESCRIPTION</Property></StyleOverride>" oPartNumber = "<StyleOverride Underline='True'> - Mk <Property Document='model' PropertySet='Design Tracking Properties' Property='Part Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>PART NUMBER</Property></StyleOverride>" oStringMass = "<Br/><StyleOverride Underline='False' FontSize='0.35'>EST UNIT MASS = <PhysicalProperty PhysicalPropertyID='72449' Precision='2'>MASS</PhysicalProperty></StyleOverride>" oStringScale = "<Br/><StyleOverride FontSize='0.3'>(Scale <DrawingViewScale/>)</StyleOverride>" 'add to the view label oView.Label.FormattedText = oDescription & oPartNumber & oStringMass & oStringScale Else MessageBox.Show("The selected object is not a drawing view", "iLogic") End If
Also see the attached text file in case the posted code has line break issues.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Thanks Curtis appreciate the help, that adds the mass exactly the way I want it.
Steve
Good morning all,
Looking this code, I remember something that I was trying to do.
If I'm on the IDW getting the details of one IAM, in one view with just one part (just one isolated), is there a way to link this view with the Parts Lists and put the label of this view as its number of the part list ? I would use that instead of put ballons in some views with details of only one part. Some years ago I used to make this way, but on CAD (manually :S), it makes the drawing a little bit "cleaner".
Thanks
Túlio Barata
I am using Curtis's solution with modifications.
I don't know much about ilogic.
I want the View Label to be Justified Left.
Can someone please tidy up my chop and hack-work please?
I think my modifications are very messy.
This is what I've done:
SyntaxEditor Code Snippet
'Adds View Label under plate that includes Item, Part Number, Profile, Material & Quantity Dim oSSet As SelectSet = ThisDoc.Document.SelectSet If oSSet.count = 0 Then MessageBox.Show("You must select a drawing view first", "iLogic") Exit Sub End If 'Reference to the drawing view from the 1st selected object Dim oView As DrawingView = trycast(oSSet.item(1), DrawingView) If oView IsNot Nothing Then oView.ShowLabel = True 'format the model iproperties oStringStock = "<StyleOverride Underline='True'>ITEM <Property Document='model' PropertySet='Design Tracking Properties' Property='Stock Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>STOCK NUMBER</Property></StyleOverride>" oStringScale = "<StyleOverride FontSize='0.2'> FLAT VIEW (<DrawingViewScale/>)</StyleOverride>" oPartNumber = "<Br/><StyleOverride Underline='False' FontSize='0.2'>PART ID: <Property Document='model' PropertySet='Design Tracking Properties' Property='Part Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>PART NUMBER</Property></StyleOverride>" oStringProfile = "<Br/><StyleOverride FontSize='0.2'>PROFILE: <Property Document='model' PropertySet='Design Tracking Properties' Property='Description' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='29'>DESCRIPTION</Property></StyleOverride>" oStringMaterial = "<Br/><StyleOverride Underline='False' FontSize='0.2'>MATERIAL: <Property Document='model' PropertySet='Design Tracking Properties' Property='Material' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='20'>PART NUMBER</Property></StyleOverride>" oStringAuth = "<Br/><StyleOverride Underline='False' FontSize='0.2'>QTY: <Property Document='model' PropertySet='Design Tracking Properties' Property='Authority' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>AUTHORITY</Property></StyleOverride>" 'add to the view label oView.Label.FormattedText = oStringStock & oStringScale & oPartNumber & oStringProfile & oStringMaterial & oStringAuth Else MessageBox.Show("The selected object is not a drawing view", "iLogic") End If Dim oDoc As DrawingDocument = ThisDoc.Document Dim oSheet As Sheet = oDoc.ActiveSheet For Each oView In oSheet.DrawingViews If Not oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft Then oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft End If Next
I've changed it to this:
SyntaxEditor Code Snippet
'Adds View Label under plate that includes Item, Part Number, Profile, Material & Quantity Dim oSSet As SelectSet = ThisDoc.Document.SelectSet Dim oDoc As DrawingDocument = ThisDoc.Document Dim oSheet As Sheet = oDoc.ActiveSheet If oSSet.count = 0 Then MessageBox.Show("You must select a drawing view first", "iLogic") Exit Sub End If 'Reference to the drawing view from the 1st selected object Dim oView As DrawingView = trycast(oSSet.item(1), DrawingView) If oView IsNot Nothing Then oView.ShowLabel = True 'format the model iproperties oStringStock = "<StyleOverride Underline='True'>ITEM <Property Document='model' PropertySet='Design Tracking Properties' Property='Stock Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>STOCK NUMBER</Property></StyleOverride>" oStringScale = "<StyleOverride FontSize='0.2'> FLAT VIEW (<DrawingViewScale/>)</StyleOverride>" oPartNumber = "<Br/><StyleOverride Underline='False' FontSize='0.2'>PART ID: <Property Document='model' PropertySet='Design Tracking Properties' Property='Part Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>PART NUMBER</Property></StyleOverride>" oStringProfile = "<Br/><StyleOverride FontSize='0.2'>PROFILE: <Property Document='model' PropertySet='Design Tracking Properties' Property='Description' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='29'>DESCRIPTION</Property></StyleOverride>" oStringMaterial = "<Br/><StyleOverride Underline='False' FontSize='0.2'>MATERIAL: <Property Document='model' PropertySet='Design Tracking Properties' Property='Material' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='20'>PART NUMBER</Property></StyleOverride>" oStringAuth = "<Br/><StyleOverride Underline='False' FontSize='0.2'>QTY: <Property Document='model' PropertySet='Design Tracking Properties' Property='Authority' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>AUTHORITY</Property></StyleOverride>" 'add to the view label oView.Label.FormattedText = oStringStock & oStringScale & oPartNumber & oStringProfile & oStringMaterial & oStringAuth oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft Else MessageBox.Show("The selected object is not a drawing view", "iLogic") End If
Thank you all for the codes.
They were very useful for me this week.
I have a little question though.…
When I enter a specific 'FontSize' (Text height) the value turns out to be in centimeters.
e.g. FontSize='0.2' stands for 0.2 cm
Is there a way for this value to be in another unit of measure?
e.g. in inches.
Thank you.
Hi all,
I would like to modify this code to make my label like this...
<VIEW IDENTIFIER>
<PART NUMBER> - <DESCRIPTION>
<STOCK NUMBER> - <MATERIAL>
SCALE <SCALE>
The formatting in the template should be fine.
Right now I add the part number, description, stock number & material by editing each label. Would save me tons of time to just run a rule.
Thanks to @Curtis_Waguespack for the original code.
Any help would be greatly appreciated.
Thanks, Steven
You can set your view label up just as you want to see it in an example drawing, and then run this rule to get the formatted text from that view.
Then you can create a rule to write out the formatted text as needed.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet Dim oDoc As DrawingDocument = ThisDoc.Document Dim oSheet As Sheet = oDoc.ActiveSheet If oSSet.Count = 0 Then MessageBox.Show("You must select a drawing view first", "iLogic") Exit Sub End If 'Reference to the drawing view from the 1st selected object Dim oView As DrawingView = TryCast(oSSet.Item(1), DrawingView) If oView IsNot Nothing Then oView.ShowLabel = True InputBox("This is the formatted text" & i, "ilogic", oView.Label.FormattedText)
Thank you @Curtis_Waguespack !
Took me a bit to figure out how to incorporate it, but it works perfect.
Thanks so much for all the education you bring!
Steven