Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
_bmiller_
988 Views, 17 Replies

FLAT PATTERN DIMS FILLED OUT AND ADDED TO PARAMETERS

Getting stuck on this one. i have a rule to fire in a sheet metal part that will add parameters and up date them with flat extents, this works fine but i need it to fire from assembly and catch each sheetmetal part in assembly. if parameters exist then it updates them if it dont exist then it adds them and updates them.

 

this is the simple rule:

Sub Main



	' Check if the active document is a part document
	Dim curDoc = ThisApplication.ActiveDocument
	If curDoc.DocumentType = kPartDocumentObject Then
	Else
		' Display an error message if the document is not a part document
		'        MessageBox.Show("This document is not a Sheet Metal Document and can not be run in this document ", "Ope Sorry!")
		Exit Sub
	End If

	' Get the active document
	Dim oDoc As PartDocument
	oDoc = ThisApplication.ActiveDocument

	' Get the component definition of the document
	Dim oDef As PartComponentDefinition
	oDef = oDoc.ComponentDefinition

	' Check if the document subtype indicates it's a sheet metal document
	If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
	Else
		' Display an error message if the document is not a sheet metal document
		'        MessageBox.Show("This document is not a Sheet Metal Document and can not be run in this document ", "Ope Sorry!")
		Exit Sub
	End If

	' Get the parameters of the component definition
	Dim oparams As Parameters
	Dim oparam As Parameter
	oparams = oDoc.ComponentDefinition.Parameters

	' Check if the parameters for flat extents length and width already exist
	Dim ExtentsLengthExists As Boolean = False
	Dim ExtentsWidthExists As Boolean = False
	For Each oparam In oparams
		If oparam.Name = "DIMA" Then ExtentsLengthExists = True
		If oparam.Name = "DIMB" Then ExtentsWidthExists = True
	Next oparam

	' Update or add the parameters for flat extents length and width

	If ExtentsLengthExists Then
		oparams.Item("DIMA").Value = SheetMetal.FlatExtentsLength * 2.54
	Else
		oparams.UserParameters.AddByValue("DIMA", SheetMetal.FlatExtentsLength * 2.54, "in")
	End If

	If ExtentsWidthExists Then
		oparams.Item("DIMB").Value = SheetMetal.FlatExtentsWidth * 2.54
	Else
		oparams.UserParameters.AddByValue("DIMB", SheetMetal.FlatExtentsWidth * 2.54, "in")
	End If

	' Set the parameters to be exposed as properties
	oparams.Item("DIMA").ExposedAsProperty = True
	oparams.Item("DIMB").ExposedAsProperty = True

	' Format the custom properties
	Dim oParameter As Parameter
	For Each oParameter In oDoc.ComponentDefinition.Parameters.UserParameters
		Try
			Dim oFormat As CustomPropertyFormat
			oFormat = oParameter.CustomPropertyFormat
			oFormat.ShowUnitsString = False
			oFormat.ShowLeadingZeros = False
			oFormat.ShowTrailingZeros = False
			oFormat.Precision = kThreeDecimalPlacesPrecision
		Catch
		End Try

	Next oParameter

	' Check if the project description is empty and prompt user to enter a description
	'    Dim description As String
	'    If iProperties.Value("Project", "Description") = "" Then
	'        description = InputBox("There is no description entered. Please enter one now. This message box will only appear if the Description field in iProperties is empty.", "Enter Description", "Description")
	'        iProperties.Value("Project", "Description") = description
	'    End If

	' Update the document
	oDoc.Update

	' Set iLogic to update when done
	iLogicVb.UpdateWhenDone = True
End Sub