Error when divide properties

Error when divide properties

Neuzzo
Advocate Advocate
501 Views
9 Replies
Message 1 of 10

Error when divide properties

Neuzzo
Advocate
Advocate

Hi, i try to divide the total area of flat sheet to convert mm3 to m3

How i can solve?

Thank you

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject And _
	ThisApplication.ActiveDocument.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value <> "Sheet Metal" Then
	MsgBox("This rule only works for Sheet Metal Part documents. Exiting.", vbOKOnly, " ")
	Exit Sub
End If

Dim oDTProps As PropertySet = ThisApplication.ActiveDocument.PropertySets.Item("Design Tracking Properties")

Dim oSMW As String = oDTProps.Item("Sheet Metal Width").Value
Dim oSML As String = oDTProps.Item("Sheet Metal Length").Value
oSMA = oDTProps.Item("Sheet Metal Area").Value / 1000
Dim Mass As String
'If iProperties.Material = "801171 AISI 304 sp.1 2B"
'	Mass = (oSMA 
MsgBox("Sheet Metal Width = " & oSMW & vbCrLf & _
"Sheet Metal Length = " & oSML & vbCrLf & _
"Sheet Metal Area = " & oSMA, vbOKOnly, "SHEET METAL SIZE")

 

Neuzzo_0-1668514563959.png

 

Danilo "DannyGi" G.
Mechanical design engineer and product developer
0 Likes
Accepted solutions (1)
502 Views
9 Replies
Replies (9)
Message 2 of 10

tyler.warner
Advocate
Advocate

Use the Double type instead of String type for your parameters since the values are decimals.

 

Dim oSMW As Double = oDTProps.Item("Sheet Metal Width").Value
Dim oSML As Double = oDTProps.Item("Sheet Metal Length").Value
Dim oSMA As Double = oDTProps.Item("Sheet Metal Area").Value / 1000


There are also cleaner ways of converting units by using the built in UnitsOfMeasure.ConvertUnits function. You can find many examples in the documentation or within the forums .

 

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes
Message 3 of 10

Neuzzo
Advocate
Advocate

Same error...

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject And _
	ThisApplication.ActiveDocument.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value <> "Sheet Metal" Then
	MsgBox("This rule only works for Sheet Metal Part documents. Exiting.", vbOKOnly, " ")
	Exit Sub
End If

Dim oDTProps As PropertySet = ThisApplication.ActiveDocument.PropertySets.Item("Design Tracking Properties")

Dim oSMW As Double = oDTProps.Item("Sheet Metal Width").Value
Dim oSML As Double = oDTProps.Item("Sheet Metal Length").Value
Dim oSMA As Double = oDTProps.Item("Sheet Metal Area").Value / 1000
Dim Mass As String
'If iProperties.Material = "801171 AISI 304 sp.1 2B"
'	Mass = (oSMA 
MsgBox("Sheet Metal Width = " & oSMW & vbCrLf & _
"Sheet Metal Length = " & oSML & vbCrLf & _
"Sheet Metal Area = " & oSMA, vbOKOnly, "SHEET METAL SIZE")

Neuzzo_0-1668521650517.png

 

Danilo "DannyGi" G.
Mechanical design engineer and product developer
0 Likes
Message 4 of 10

tyler.warner
Advocate
Advocate

What are "Sheet Metal Width", etc? Are those user parameters or custom iProperties?

 

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes
Message 5 of 10

Neuzzo
Advocate
Advocate
Really don't know 😐
Danilo "DannyGi" G.
Mechanical design engineer and product developer
0 Likes
Message 6 of 10

tyler.warner
Advocate
Advocate

Can you provide a sample part file?

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes
Message 7 of 10

Neuzzo
Advocate
Advocate

Yes. Here the sheet metal

Danilo "DannyGi" G.
Mechanical design engineer and product developer
0 Likes
Message 8 of 10

tyler.warner
Advocate
Advocate
Accepted solution

Try something like this:

 

 

Sub Main

	Dim oDocument As Document = ThisApplication.ActiveDocument
	If oDocument.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
		MsgBox("The open file is not a part file. The command has been cancelled.")
		Exit Sub
	End If

	Dim oPartDocument As PartDocument = oDocument
	If oPartDocument.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
		MsgBox("This is not a sheet metal part. The command has been cancelled.")
		Exit Sub
	End If
	
	Dim oComponentDefinition As SheetMetalComponentDefinition = oPartDocument.ComponentDefinition
	Dim oFlatPattern As FlatPattern = oComponentDefinition.FlatPattern
	Dim oUOM As UnitsOfMeasure = oPartDocument.UnitsOfMeasure
	
	Dim oSMW As Double = oUOM.ConvertUnits(oFlatPattern.Width, UnitsTypeEnum.kDatabaseLengthUnits, UnitsTypeEnum.kMillimeterLengthUnits) 'Database unit is cm
	MsgBox("Width (mm): " & oSMW)
	
	Dim oSML As Double = oUOM.ConvertUnits(oFlatPattern.Length, UnitsTypeEnum.kDatabaseLengthUnits, UnitsTypeEnum.kMillimeterLengthUnits) 'Database unit is cm
	MsgBox("Length (mm): " & oSML)
	
	Dim oSMA As Double = oSMW * oSML
	MsgBox("Area (mm): " & oSMA)
	
End Sub

 

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes
Message 9 of 10

WCrihfield
Mentor
Mentor

Hi guys.  Those were standard iProperties that are present in all Inventor documents, but obviously only used in sheet metal parts.  There are actually two different series of similar standard iProperties for similar purposes, and both are in the same PropertySet.  Item(44) is "Flat Pattern Width" with PropID = 63.  Item(45) is "Flat Pattern Length", with PropId = 64.  Item(46) is "Flat Pattern Area", with PropId = 65.  And you already know about the 3 starting with "Sheet Metal ...", but all of those are ReadOnly, and should all return Double data type, but all iProperty.Value is defined as Object, so it is always best to set the value of a variable of the expected data type, before attempting to do things like math with an expected Double, because the Value is not yet recognized as a Double until it is assigned to a Double type variable.  I believe one of these sets is supposed to return document units, while the other returns database units.  The iLogic shortcut snippets (SheetMetal.FlatExtentsWidth) actually access these iProperties behind the scenes.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 10

Neuzzo
Advocate
Advocate
Work like a charm. Thank you
Danilo "DannyGi" G.
Mechanical design engineer and product developer
0 Likes