Rule flat pattern export fails, when custom property is not created

Rule flat pattern export fails, when custom property is not created

vkulikajevas
Advocate Advocate
443 Views
1 Reply
Message 1 of 2

Rule flat pattern export fails, when custom property is not created

vkulikajevas
Advocate
Advocate

I have this Flat pattern rule. The problem comes with naming. When part does not have a Custom parameter (iQTY), rule does not export DXF. 

Can this line be tweaked, so that when iQTY does not exist, it would just insert nothing and export anyway?

vkulikajevas_0-1621959363582.png

 

 

Dim oDoc As Document = ThisDoc.Document
'Dim ovnt As String = InputBox("Detalių kiekis", "VNT", "1")

	If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then

		Dim oCompDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition
		
		If oCompDef.HasFlatPattern = False Then 
			oCompDef.Unfold
		Else
			oCompDef.FlatPattern.Edit
		End If
			
		Try
			oMaterial = oDoc.ComponentDefinition.Material.Name
			oThickness = Round(oDoc.ComponentDefinition.Thickness.Value*10, 2)'Convert cm to inch
			oStockNumber = oDoc.PropertySets.Item("Design Tracking Properties").Item("Stock Number").Value
			oDescription = oDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value
			oPartNumber = oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
			
			iQTY = oDoc.PropertySets.Item("Inventor User Defined Properties").Item("iQTY").Value


			Dim oFilename As String  = ThisDoc.Path & "\" &  oPartNumber  & " " & oMaterial & " " & oStockNumber & " " & iQTY  & "vnt.dxf"
			
			MessageBox.Show(oFilename)
			
			Dim oDataIO As DataIO = oDoc.ComponentDefinition.DataIO
    		oDataIO.WriteDataToFile("FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0&InvisibleLayers=IV_ARC_CENTERS;IV_TANGENT;IV_ROLL;IV_ROLL_TANGENT;IV_ALTREP_BACK;IV_ALTREP_FRONT;IV_FEATURE_PROFILES_DOWN;IV_FEATURE_PROFILES;IV_TOOL_CENTER_DOWN;IV_BEND;IV_BEND_DOWN", oFilename)
			oCompDef.FlatPattern.ExitEdit
		Catch
	
		End Try		
	End If	

 

 

0 Likes
Accepted solutions (1)
444 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor
Accepted solution

How about if that variable is set to an empty string, when that custom property doesn't exist.  Then you don't have to alter your complicated file name string.  You can do that like this:

Replace this line:

iQTY = oDoc.PropertySets.Item("Inventor User Defined Properties").Item("iQTY").Value

with this block of code:

Dim iQTY As String
Try
	iQTY = oDoc.PropertySets.Item("Inventor User Defined Properties").Item("iQTY").Value
Catch
	iQTY = ""
End Try

You could also use that Catch portion of the Try...Catch block to create the custom iProperty if you wanted.  Or to run some other rule or sub that would create it, and set its value.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)