SHEET METAL EXTENTS: CREATE CUST PROPS IN MODEL FROM RULE IN DRAWING

SHEET METAL EXTENTS: CREATE CUST PROPS IN MODEL FROM RULE IN DRAWING

RoyWickrama_RWEI
Advisor Advisor
1,173 Views
4 Replies
Message 1 of 5

SHEET METAL EXTENTS: CREATE CUST PROPS IN MODEL FROM RULE IN DRAWING

RoyWickrama_RWEI
Advisor
Advisor
  • Custom Property: SheetMetalLength
  • Custom Property: SheetMetalWidth

2019-07-11 22_33_10-Window.png

Having build up the model, I assign almost all the iProperties at the time of details the document (part, sheet metal part, derived part, assembly, drawing itself, ..) at thetimeof creating the production drawings.

My current rule is comprehensive and doing well, but it is lacking of creating custom properties in case the model in the drawing is a sheet metal part.

I was not successful although I spent a lot of time.

 

'Get active document
Dim oDoc_in_Dwg As Document
oDoc_in_Dwg = ThisDoc.ModelDocument
'Get active document unit of measure
Dim uom As UnitsOfMeasure = oDoc_in_Dwg.UnitsOfMeasure
'Converts length unit to a string
Dim Units As String = uom.GetStringFromType(uom.LengthUnits)

'Checks To see If the active document Is a standard part
If oDoc_in_Dwg.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Then
'If it Is a standard part we convert it to sheet metal
   Try
      oDoc_in_Dwg.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
   Catch
      'catch error and exit rule when part can't be converted
      'example: multiple solid body part
      Return
   End Try
End If

'Check if the part is sheet metal now
If oDoc_in_Dwg.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then

   'Go To the FlatPattern
   Dim oSMCD As SheetMetalComponentDefinition
   oSMCD = oDoc_in_Dwg.ComponentDefinition
   'Look For Flatpattern
   If Not oSMCD.HasFlatPattern Then
      'Create Flatpattern If the part doesn't have one
      oSMCD.Unfold()
      oDoc_in_Dwg.Update2(True)
      oSMCD.FlatPattern.ExitEdit()
	Else
		MessageBox.Show("SHEET METAL " & "Flat Pattern found", "Title")
		'https://forums.autodesk.com/t5/inventor-forum/ilogc-rule-to-delete-2-user-parameters-and-create-2-custom/td-p/6486777
		'suppress user parameters
		Dim Width As String = "SheetMetalWidth"
		Dim Length As String = "SheetMetalLength"
		Dim oDef As ComponentDefinition = oDoc_in_Dwg.ComponentDefinition
		Try
		Dim oParW As UserParameter = oDef.Parameters.UserParameters.item(Width)
		Dim oParL As UserParameter = oDef.Parameters.UserParameters.item(Length)
		oParW.Delete
		oParL.Delete
		oDoc_in_Dwg.Update
		Catch
		MessageBox.Show("User parameter don't exist", "iLogic rule")
'		Return 'exit rule
		End Try

	iProperties.Value(oDoc_in_Dwg, "Custom", "SheetMetalLength")=Round(SheetMetal.FlatExtentsLength,2)
	iProperties.Value(oDoc_in_Dwg, "Custom", "SheetMetalWidth")=Round(SheetMetal.FlatExtentsWidth,2)

	End If
End If

Rule and Samples attached.

Inv 2019 Professional/Vault Professional

0 Likes
Accepted solutions (1)
1,174 Views
4 Replies
Replies (4)
Message 2 of 5

JamieVJohnson2
Collaborator
Collaborator
According to this, your Property Set name should be Design Tracking Properties, not Custom (Inventor User Defined Properties).
 
{Property Set Name}
{Property.DisplayName, Property.Name, Property.ID, Property.Type, Property.Expression, Property.Value}
Inventor Summary Information
      Title, Title, 2, 50339072, ,
      Subject, Subject, 3, 50339072, ,
      Author, Author, 4, 50339072, Roy Wickrama, Roy Wickrama
      Keywords, Keywords, 5, 50339072, ,
      Comments, Comments, 6, 50339072, ,
      Last Saved By, Last Saved By, 8, 50339072, ,
      Revision Number, Revision Number, 9, 50339072, 0, 0
Inventor Document Summary Information
      Category, Category, 2, 50339072, ,
      Manager, Manager, 14, 50339072, ,
      Company, Company, 15, 50339072, Mainland Machinery Ltd., Mainland Machinery Ltd.
Design Tracking Properties
      Date Created, Creation Time, 4, 50339072, 4/30/2019, 4/30/2019 5:24:36 PM
      Part Number, Part Number, 5, 50339072, M3D121 - Forum, M3D121 - Forum
      Project, Project, 7, 50339072, ,
      Cost Center, Cost Center, 9, 50339072, ,
      Checked by, Checked By, 10, 50339072, ,
      Date Checked, Date Checked, 11, 50339072, , 1/1/1601
      Engr Approved by, Engr Approved By, 12, 50339072, ,
      Date Eng Approved, Engr Date Approved, 13, 50339072, , 1/1/1601
      User Status, User Status, 17, 50339072, ,
      Material, Material, 20, 50339072, Steel, Mild, Steel, Mild
      Part Revision, Part Property Revision Id, 21, 50339072, {D0464DBB-1083-4560-904C-1409532C7E41}, {D0464DBB-1083-4560-904C-1409532C7E41}
      Catalog web link, Catalog Web Link, 23, 50339072, ,
      Part Icon, Part Icon, 28, 50339072, (NULL),
      Description, Description, 29, 50339072, ,
      Vendor, Vendor, 30, 50339072, ,
      Part Type, Document SubType, 31, 50339072, {9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}, {9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}
      Part Type name, Document SubType Name, 32, 50339072, Sheet Metal, Sheet Metal
      Date proxy refreshed, Proxy Refresh Date, 33, 50339072, , 1/1/1601
      Mfg Approved by, Mfg Approved By, 34, 50339072, ,
      Date Mfg Approved, Mfg Date Approved, 35, 50339072, , 1/1/1601
      Cost, Cost, 36, 50339072, , 0.0000
      Standard, Standard, 37, 50339072, ,
      Design Status, Design Status, 40, 50339072, 1, 1
      Designer, Designer, 41, 50339072, ANH, ANH
      Engineer, Engineer, 42, 50339072, ,
      Authority, Authority, 43, 50339072, ,
      Parameterized Template, Parameterized Template, 44, 50339072, No, False
      Template Row, Template Row, 45, 50339072, ,
      External Part Revision, External Property Revision Id, 46, 50339072, {B44B8D67-329B-4537-A130-880B1599604C}, {B44B8D67-329B-4537-A130-880B1599604C}
      Standard Revision, Standard Revision, 47, 50339072, ,
      Manufacturer, Manufacturer, 48, 50339072, ,
      Standards Organization, Standards Organization, 49, 50339072, ,
      Language, Language, 50, 50339072, ,
      Defer Updates, Defer Updates, 51, 50339072, No, False
      Size Designation, Size Designation, 52, 50339072, ,
      Categories, Categories, 56, 50339072, ,
      Stock Number, Stock Number, 55, 50339072, ,
      Weld Material, Weld Material, 57, 50339072, ,
      Mass, Mass, 58, 50339072, 266.12353292, 266.xxx-xxxxxxxx
      SurfaceArea, SurfaceArea, 59, 50339072, 117.14784652, 117.147846520301
      Volume, Volume, 60, 50339072, 33.901087, 33.9010869964394
      Density, Density, 61, 50339072, 7.85, 7.85
      Valid MassProps, Valid MassProps, 62, 50339072, 17, 17
      FlatPatternExtentsWidth, Flat Pattern Width, 63, 50339072, 5, 4.99999999999997
      FlatPatternExtentsLength, Flat Pattern Length, 64, 50339072, 9.5, 9.5
      FlatPatternExtentsArea, Flat Pattern Area, 65, 50339072, 47.5, 47.4999999999997
      SheetMetalRule, Sheet Metal Rule, 66, 50339072, PL 0.313 (5/16"), PL 0.313 (5/16")
      LastUpdatedWith, Last Updated With, 67, 50339072, 2019.4 (Build 234330000, 330), 2019.4 (Build 234330000, 330)
      SheetMetalWidth, Sheet Metal Width, 68, 50339072, 1.969 in, 1.969 in
      SheetMetalLength, Sheet Metal Length, 69, 50339072, 3.740 in, 3.740 in
      SheetMetalArea, Sheet Metal Area, 70, 50339072, 7.363 in^2, 7.363 in^2
      Material Identifier, Material Identifier, 71, 50339072, C:\Users\Public\Documents\Autodesk\Inventor 2015\Design Data\Materials\InventorMaterialLibrary.adsklib#1:Steel, Mild
#MaterialInv_029, C:\Users\Public\Documents\Autodesk\Inventor 2015\Design Data\Materials\InventorMaterialLibrary.adsklib#1:Steel, Mild
#MaterialInv_029
      Appearance, Appearance, 72, 50339072, Steel, Steel
      Flat Pattern Defer Update, Flat Pattern Defer Update, 73, 50339072, No, False
Inventor User Defined Properties
      Thickness, Thickness, 79, 50339072, 0.313 in, 0.313 in
      ipwFlatExtentsZ, ipwFlatExtentsZ, 80, 50339072, 0.313 in, 0.313 in
Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
Message 3 of 5

RoyWickrama_RWEI
Advisor
Advisor

I see that all data of the model document retrieved. Amazing. I never thought this way. I am eager to know how you did and I apologize you, but could you provide me with more details and the code as well. I will explore each and every line of code (step) and understand the procedure.

Thanks a lot.

0 Likes
Message 4 of 5

Sergio.D.Suárez
Mentor
Mentor
Accepted solution
It is not necessary to create a custom property to catch this value in it, you can access directly through the lines of the example

 

oView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select View")
If oView Is Nothing Then Exit Sub

oViewModelDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
		
If oViewModelDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
	Dim oDef As SheetMetalComponentDefinition = oViewModelDoc.ComponentDefinition
	If oDef.HasFlatPattern = False Then 
		oDef.Unfold
		oDef.FlatPattern.ExitEdit
		oViewModelDoc.close
	End If
	
	oSheetMetalLength = Round(oDef.FlatPattern.Length,2)'Default value in cm
	oSheetMetalWidth = Round(oDef.FlatPattern.Width, 2)'Default value in cm
	
	MessageBox.Show(oSheetMetalLength)
	MessageBox.Show(oSheetMetalWidth)

End If

If you want to create a custom property with this value, perhaps it would serve a path like the one of continuation

Dim PropA As String = "Sheet Metal Length ->"
Dim PropB As String = "Sheet Metal Width ->"

Line1 :
oView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select View")
If oView Is Nothing Then Exit Sub

oViewModelDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
		
If oViewModelDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
	Dim oDef As SheetMetalComponentDefinition = oViewModelDoc.ComponentDefinition
	If oDef.HasFlatPattern = False Then 
		oDef.Unfold
		oDef.FlatPattern.ExitEdit
		oViewModelDoc.close
	End If
	
	oSheetMetalLength = Round(oDef.FlatPattern.Length,2)'Default value in cm
	oSheetMetalWidth = Round(oDef.FlatPattern.Width, 2)'Default value in cm
	
	Dim oCustPropertySet As PropertySet = oViewModelDoc.PropertySets.Item("Inventor User Defined Properties")
	Try  
	oCustPropertySet.Add(oSheetMetalLength, PropA)
	Catch
	oCustPropertySet.Item(PropA).Value = oSheetMetalLength & " cm"	
	End Try
		
	Try  
	oCustPropertySet.Add(oSheetMetalWidth, PropB)
	Catch
	oCustPropertySet.Item(PropB).Value = oSheetMetalWidth & " cm"
	End Try
End If

goto Line1

I hope this helps. regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 5 of 5

JamieVJohnson2
Collaborator
Collaborator

Read Property Sets is a pretty simple routine, I found and modified from here years ago, Here is my version, that ran the view you see above:

    Public Sub ReadOutPropertySets(invDoc As Inventor.Document)
        Try
            Dim strPropertySets As String = "Inventor Property Sets" & vbCrLf & "{Property Set Name}" & vbCrLf & "{Property.DisplayName, Property.Name, Property.ID, Property.Type, Property.Expression, Property.Value}"
            For Each pset As PropertySet In invDoc.PropertySets
                strPropertySets += vbCrLf & pset.Name
                For Each prop As [Property] In pset
                    Try
                        strPropertySets += vbCrLf & "      " & prop.DisplayName & ", " & prop.Name & ", " & prop.PropId & ", " & prop.Type & ", " & prop.Expression & ", " & prop.Value
                    Catch ex As Exception
                    End Try
                Next
            Next
            MsgBox(strPropertySets)
        Catch ex As Exception
        End Try
    End Sub
Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/