I logic for derived part

I logic for derived part

didin.suryadi6JREK
Advocate Advocate
1,580 Views
16 Replies
Message 1 of 17

I logic for derived part

didin.suryadi6JREK
Advocate
Advocate

Hi,

 

I have below i-logic to delete the specific user parameters on the part, But somehow it doesn't work for the derived part.

(the part with 2d file referenced), Is there any additional logic to add to make both are working?

 

'------- @_@ start of ilogic @_@ ------

Dim oDoc As PartDocument = ThisDoc.Document
Dim doc = ThisDoc.Document
For Each oParam As Parameter In doc.componentdefinition.Parameters.UserParameters
oParam.Delete
Next

 

I think the problem is on "ThisDoc" when it hits another source. 

0 Likes
Accepted solutions (1)
1,581 Views
16 Replies
Replies (16)
Message 2 of 17

A.Acheson
Mentor
Mentor

This post semi deals with the situation your looking at. Nothing was marked as solved but I believe the VBA at the end has worked. The term delete may not be correct as you are just unlinking from the parent file so as such need to either include or exclude the parameter. 
https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/deleting-derived-parameters-that-are-no...

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 17

didin.suryadi6JREK
Advocate
Advocate

Hi,

 

Thanks for the idea, Could you please check wheater the below arrangement is correct or not?

 

'------- @_@ start of ilogic @_@ ------

Dim oDoc As PartDocument = ThisDoc.Document
Dim doc = ThisDoc.Document
For Each oParam As Parameter In doc.componentdefinition.Parameters.UserParameters
	oParam.Delete
Next
For Each oDerivedParameter As DerivedParameter In DerivedParameterTable.DerivedParameters
If Not oDerivedParameter.InUse Then oDerivedParameter.Delete
Next  

The Error msg shown like below:

Rule Compile Errors in Conversion Rule Part, in Test.ipt

Error on Line 8 : Reference to a non-shared member requires an object reference.

 

0 Likes
Message 4 of 17

A.Acheson
Mentor
Mentor

Here is a working rule to derive all parameters from the base component to a derived part file. 

You can put in filters if you want to target only specific parameters to include/exclude. I would suggest use it on a sample file as it could really mess up the part until your sure of it's function. 

I found this rule from here,  I just removed it from the for loop for the assembly document it was been used in. 

Change this line "oDPEnt.IncludeEntity = True 'True to include, False to exclude!" to control the parameters included /excluded .

 

 

Dim doc As Document = ThisDoc.Document
	If doc.DocumentType = 12290 Then 'part file
		Dim oDPComp As DerivedPartComponent
		Dim oDPComps As DerivedPartComponents
		oDPComps = doc.ComponentDefinition.ReferenceComponents.DerivedPartComponents
		
			For x = 1 To oDPComps.Count
				oDPComp = oDPComps.Item(x)
				Dim oDPDef As DerivedPartUniformScaleDef = oDPComp.Definition 
				Dim oDPEnts As DerivedPartEntities = oDPDef.Parameters
				Dim oDPEnt As DerivedPartEntity
					'Loop to include/exclude parameters
					For Each oDPEnt In oDPEnts
						'Filter for specific parameter
						'If oDPEnt.ReferencedEntity.Name = "Length" Then ' Add your parameter name here!
							oDPEnt.IncludeEntity = True 'True to include, False to exclude!
							'Exit For
						'End If
					Next
			oDPComp.Definition = oDPDef
			Next
	End If

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 5 of 17

didin.suryadi6JREK
Advocate
Advocate

Hi,

Thanks

 

The code works fine but somehow when I run it on the derived part it's taking longer than I thought. 

It's was finished about 50 secs to 1 minute of executing the base part.

 

Can we push the speed of the time to be faster?

 

Appreciated your prompt response.

 

0 Likes
Message 6 of 17

A.Acheson
Mentor
Mentor

I didn’t see any issues on my side, I had 5 parameters and ran the rule looked in the parameters dialogue and they were done, I used single value parameters. Can you try a message box or a log info message at each stage to check progress. There must be a logical  reason it took so long to execute. Please supply the full rule if placed inside a larger rule. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 7 of 17

didin.suryadi6JREK
Advocate
Advocate

Hi,

 

Below are the complete codes, Could you please check? 

I don't understand why the error msg comes when I ran the codes.

 

'------- @_@ start of ilogic @_@ ------

Dim oDoc As PartDocument = ThisDoc.Document
Dim doc = ThisDoc.Document
For Each oParam As Parameter In doc.componentdefinition.Parameters.UserParameters
oParam.Delete

Next
	If doc.DocumentType = 12290 Then 'part file
		Dim oDPComp As DerivedPartComponent
		Dim oDPComps As DerivedPartComponents
		oDPComps = doc.ComponentDefinition.ReferenceComponents.DerivedPartComponents
		
			For x = 1 To oDPComps.Count
				oDPComp = oDPComps.Item(x)
				Dim oDPDef As DerivedPartUniformScaleDef = oDPComp.Definition 
				Dim oDPEnts As DerivedPartEntities = oDPDef.Parameters
				Dim oDPEnt As DerivedPartEntity
					'Loop to include/exclude parameters
					For Each oDPEnt In oDPEnts
						'Filter for specific parameter
						'If oDPEnt.ReferencedEntity.Name = "Length" Then ' Add your parameter name here!
							oDPEnt.IncludeEntity = True 'True to include, False to exclude!
							'Exit For
						'End If
					Next
			oDPComp.Definition = oDPDef
			Next
	End If

error msg.JPG
error msg2.JPG

 

0 Likes
Message 8 of 17

A.Acheson
Mentor
Mentor

The error I believe is coming when your looking to delete the user parameters from the child document. oParam was declared as a Parameter in the User parameter collection. As it was there was no delete function as your looking for the wrong object in that collection. If you declare oParam as a UserParameter the delete function is accessible.

 

This is a good example of declaring variables starting with the document and checking what is available after declaring. 

 

Dim doc As PartDocument = ThisDoc.Document
For Each oParam As UserParameter In doc.componentdefinition.Parameters.UserParameters
oParam.Delete

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 9 of 17

didin.suryadi6JREK
Advocate
Advocate

Hi

 

Thanks,

Sorry for not being clear on this

Actually, I have the previous codes with oDoc to be included, so Both are needed.

How's that possible to combine Doc and oDoc I with the same i-logic codes?

Could you please review the below codes? I ran it and still error, the error msg is the same.

=======================================================================


Dim oDoc As PartDocument = ThisDoc.Document
Dim doc = ThisDoc.Document
For Each oParam As Parameter In doc.componentdefinition.Parameters.UserParameters
oParam.Delete

Next

If doc.DocumentType = 12290 Then 'part file
Dim oDPComp As DerivedPartComponent
Dim oDPComps As DerivedPartComponents
oDPComps = doc.ComponentDefinition.ReferenceComponents.DerivedPartComponents

For x = 1 To oDPComps.Count
oDPComp = oDPComps.Item(x)
Dim oDPDef As DerivedPartUniformScaleDef = oDPComp.Definition
Dim oDPEnts As DerivedPartEntities = oDPDef.Parameters
Dim oDPEnt As DerivedPartEntity
'Loop to include/exclude parameters
For Each oDPEnt In oDPEnts
'Filter for specific parameter
'If oDPEnt.ReferencedEntity.Name = "Length" Then ' Add your parameter name here!
oDPEnt.IncludeEntity = True 'True to include, False to exclude!
'Exit For
'End If
Next
oDPComp.Definition = oDPDef
Next
End If

'Next 'Derived part componen

'define custom property collection
Dim customPropertySet As PropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")
'look at each property in the collection
For Each oCustProp In customPropertySet
'delete the custom iProperty
oCustProp.Delete

Next

Dim propertyName1 As String = "Rev Note"
Dim propertyValue1 As String = ""

Try
prop = customPropertySet.Item(propertyName1)
Catch
customPropertySet.Add("", propertyName1)
End Try

Dim propertyName2 As String = "Revision Date"
Dim propertyValue2 As Nullable(Of Date) = Date.Now
Dim NullDate As Nullable(Of Date)
Try
prop = customPropertySet.Item(propertyName2)
Catch
customPropertySet.Add(propertyValue2, propertyName2)
iProperties.Value("Custom", propertyName2) = NullDate
End Try

Dim propertyName3 As String = "Bending Proficient"
Dim valString As String = InputBox("BendingProficient:", "Set Property", "No")
Dim propertyValue3 As Boolean = If (valString = "Yes", True, False)
Try
prop = customPropertySet.Item(propertyName3)
Catch
prop = customPropertySet.Add(propertyValue3, propertyName3)
End Try

iProperties.Value("Custom", propertyName3) = propertyValue3


Dim propertyName4 As String = "ECN_date"
Dim propertyValue4 As Nullable(Of Date) = Date.Now
Try
prop = customPropertySet.Item(propertyName4)
Catch
customPropertySet.Add(propertyValue4, propertyName4)
iProperties.Value("Custom", propertyName4) = NullDate
End Try

Dim propertyName5 As String = "ECN_ENGINEER"
Dim propertyValue5 As String = ""


Try
prop = customPropertySet.Item(propertyName5)
Catch
customPropertySet.Add(propertyValue5, propertyName5)
End Try


Dim propertyName6 As String = "ECN_NUMBER"
Dim propertyValue6 As String = ""
Try
prop = customPropertySet.Item(propertyName6)
Catch
customPropertySet.Add(propertyValue6, propertyName6)

End Try

Dim propertyName7 As String = "GRAIN_LENGTH"
Dim propertyValue7 As String = "=<Sheet Metal Length>"
Try
prop = customPropertySet.Item(propertyName7)
Catch
customPropertySet.Add(propertyValue7, propertyName7)

End Try

Dim propertyName8 As String = "GRAIN_WIDTH"
Dim propertyValue8 As String = "=<Sheet Metal Width>"
Try
prop = customPropertySet.Item(propertyName8)
Catch
customPropertySet.Add(propertyValue8, propertyName8)

End Try


Dim oUM As UnitsOfMeasure = oDoc.UnitsOfMeasure
Dim oLengthUnits As String = InputBox("Length units:", "Masukan Unit Length", oUM.GetStringFromType(oUM.LengthUnits))
Try
oUM.LengthUnits = oUM.GetTypeFromString(oLengthUnits)
Catch
MessageBox.Show("""" & oLengthUnits & """"& " is not a valid length units", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

Dim oMassUnits As String = InputBox("Mass units:", "Masukan Unit Massa", oUM.GetStringFromType(oUM.MassUnits))
Try
oUM.MassUnits = oUM.GetTypeFromString(oMassUnits)
Catch
MessageBox.Show("""" & oMassUnits & """"& " is not a valid mass units", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try


Dim oMaterials As New List(Of String)
Dim oActiveMaterial As String = oDoc.ActiveMaterial.DisplayName
For Each oMaterial As MaterialAsset In ThisApplication.ActiveMaterialLibrary.MaterialAssets
oMaterials.Add(oMaterial.DisplayName)
Next
If oMaterials.Contains(oActiveMaterial) = False Then oMaterials.Add(oActiveMaterial)

oMaterials.Sort
Dim selectedMaterial As String = InputListBox("Pilih material", oMaterials, oActiveMaterial)
Try
oDoc.ActiveMaterial = ThisApplication.ActiveMaterialLibrary.MaterialAssets.Item(selectedMaterial)
Catch
End Try

iProperties.Value("Summary", "Author") = ThisApplication.UserName
iProperties.Value("Project", "Revision Number") = InputBox("Revision Number:", "Set Property", "-")
iProperties.Value("Project", "Designer") = ThisApplication.UserName
iProperties.Value("Project", "Engineer") = ThisApplication.UserName
iProperties.Value("Project", "Creation Date") = Today
ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd").Execute
myMass = iProperties.Mass

MessageBox.Show("Mass = " & myMass, "iLogic")

===================================

 

When i skip the deletion (like in the below) then it works.

 

Dim oDoc As PartDocument = ThisDoc.Document
Dim doc = ThisDoc.Document
For Each oParam As Parameter In doc.componentdefinition.Parameters.UserParameters
'oParam.Delete


 

0 Likes
Message 10 of 17

A.Acheson
Mentor
Mentor

You can just change the part document name to whatever is the most used for document variable in your codes, use find and replace to replace them. 

 

So change doc to oDoc. It has been declared twice which isn't necessary.

 

And if you want to check the document is a part move the if statement outside of the main body of the rule. It is just there for good practice and isn't totally needed, the below methods are where you can find the information on that and how you can implement this.

 

AAcheson_0-1630461640761.png

 

AAcheson_1-1630461674090.png

Method 1

'Declare this document
Dim doc As Document
doc = ThisDoc.Document
 
'Check if we have a part document
If doc.DocumentType = 12290 Then 'part file
 Dim oDoc As PartDocument
'Make the document before checking equal to document after checking
	oDoc = doc
	
	
	'*** Insert  stuff here
Else
	MessageBox.Show("This is not a Part Exiting!", "Title")
End If

Method 2:

 'Declare this document
 Dim doc As Document
 doc = ThisDoc.Document

'Check if we have a part document
If doc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
 Dim oDoc As PartDocument
'Make the document before checking equal to document after checking
oDoc = doc Else '*** Insert stuff here MessageBox.Show("This is not a Part Exiting!", "Title") End If

 

Method 3:

'Declared Document as Part Document, it will error out if not a part document
Dim oDoc As PartDocument
 oDoc = ThisDoc.Document

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 11 of 17

didin.suryadi6JREK
Advocate
Advocate

hi

 

I tried all of your three methods but the errors are still coming, some of them seem the arrangement was wrong. Could you please check the complete codes? I just wondering why the codes are working when I turn off "oParam.Delete" ... Below Codes is working, but when i turn the on the "oParam.Delete" , the msg error is come. 

 

Dim oDoc As PartDocument = ThisDoc.Document
Dim doc = ThisDoc.Document
For Each oParam As Parameter In doc.componentdefinition.Parameters.UserParameters
'oParam.Delete

Next

	If doc.DocumentType = 12290 Then 'part file
		Dim oDPComp As DerivedPartComponent
		Dim oDPComps As DerivedPartComponents
		oDPComps = doc.ComponentDefinition.ReferenceComponents.DerivedPartComponents
		
			For x = 1 To oDPComps.Count
				oDPComp = oDPComps.Item(x)
				Dim oDPDef As DerivedPartUniformScaleDef = oDPComp.Definition 
				Dim oDPEnts As DerivedPartEntities = oDPDef.Parameters
				Dim oDPEnt As DerivedPartEntity
					'Loop to include/exclude parameters
					For Each oDPEnt In oDPEnts
						'Filter for specific parameter
						'If oDPEnt.ReferencedEntity.Name = "Length" Then ' Add your parameter name here!
							oDPEnt.IncludeEntity = True 'True to include, False to exclude!
							'Exit For
						'End If
					Next
			oDPComp.Definition = oDPDef
			Next
	End If
	
'Next 'Derived part componen

'define custom property collection
Dim customPropertySet As PropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")
'look at each property in the collection
For Each oCustProp In customPropertySet
'delete the custom iProperty
oCustProp.Delete

Next

Dim propertyName1 As String = "Rev Notes"
Dim propertyValue1 As String = ""

Try
	prop = customPropertySet.Item(propertyName1)
Catch
	customPropertySet.Add("", propertyName1)
End Try

Dim propertyName2 As String = "Revision Date"
Dim propertyValue2 As Nullable(Of Date) = Date.Now
Dim NullDate As Nullable(Of Date)
Try
	prop = customPropertySet.Item(propertyName2)
Catch
	customPropertySet.Add(propertyValue2, propertyName2)
    iProperties.Value("Custom", propertyName2) = NullDate	
End Try

Dim propertyName3 As String = "Bending Proficient"
Dim valString As String = InputBox("Salvagnini Proficient:", "Set Property", "No")
Dim propertyValue3 As Boolean = If (valString = "Yes", True, False)
Try
	prop = customPropertySet.Item(propertyName3)
Catch
	prop = customPropertySet.Add(propertyValue3, propertyName3)
End Try

iProperties.Value("Custom", propertyName3) = propertyValue3

Dim propertyName4 As String = "ECN_DATE"
Dim propertyValue4 As Nullable(Of Date) = Date.Now
Try
	prop = customPropertySet.Item(propertyName4)
Catch
	customPropertySet.Add(propertyValue4, propertyName4)
	iProperties.Value("Custom", propertyName4) = NullDate	
End Try

Dim propertyName5 As String = "ECN_ENGINEER"
Dim propertyValue5 As String = ""


Try
	prop = customPropertySet.Item(propertyName5)
Catch
	customPropertySet.Add(propertyValue5, propertyName5)
End Try


Dim propertyName6 As String = "ECN_NUMBER"
Dim propertyValue6 As String = ""
Try
	prop = customPropertySet.Item(propertyName6)
Catch
	customPropertySet.Add(propertyValue6, propertyName6)

End Try

Dim propertyName7 As String = "GRAIN_LENGTH"
Dim propertyValue7 As String = "=<Sheet Metal Length>"
Try
	prop = customPropertySet.Item(propertyName7)
Catch
	customPropertySet.Add(propertyValue7, propertyName7)

End Try

Dim propertyName8 As String = "GRAIN_WIDTH"
Dim propertyValue8 As String = "=<Sheet Metal Width>"
Try
	prop = customPropertySet.Item(propertyName8)
Catch
	customPropertySet.Add(propertyValue8, propertyName8)

End Try


Dim oUM As UnitsOfMeasure = oDoc.UnitsOfMeasure
Dim oLengthUnits As String = InputBox("Length units:", "Masukan Unit Length", oUM.GetStringFromType(oUM.LengthUnits))
Try
	oUM.LengthUnits = oUM.GetTypeFromString(oLengthUnits)
Catch
	MessageBox.Show("""" & oLengthUnits & """"& " is not a valid length units", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

Dim oMassUnits As String = InputBox("Mass units:", "Masukan Unit Massa", oUM.GetStringFromType(oUM.MassUnits))
Try
	oUM.MassUnits = oUM.GetTypeFromString(oMassUnits)
Catch
	MessageBox.Show("""" & oMassUnits & """"& " is not a valid mass units", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try


Dim oMaterials As New List(Of String)
Dim oActiveMaterial As String = oDoc.ActiveMaterial.DisplayName
For Each oMaterial As MaterialAsset In ThisApplication.ActiveMaterialLibrary.MaterialAssets
	oMaterials.Add(oMaterial.DisplayName)
Next
If oMaterials.Contains(oActiveMaterial) = False Then oMaterials.Add(oActiveMaterial)

oMaterials.Sort
Dim selectedMaterial As String = InputListBox("Pilih material", oMaterials, oActiveMaterial)
Try
oDoc.ActiveMaterial = ThisApplication.ActiveMaterialLibrary.MaterialAssets.Item(selectedMaterial)
Catch
End Try

iProperties.Value("Summary", "Author") = ThisApplication.UserName
iProperties.Value("Project", "Revision Number") = InputBox("Revision Number:", "Set Property", "-")
iProperties.Value("Project", "Designer") = ThisApplication.UserName
iProperties.Value("Project", "Engineer") = ThisApplication.UserName
iProperties.Value("Project", "Creation Date") = Today
ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd").Execute
myMass = iProperties.Mass

MessageBox.Show("Mass = " & myMass, "iLogic")



  

0 Likes
Message 12 of 17

A.Acheson
Mentor
Mentor

As long as you are deleting user parameters you can use this snippet referred to in Message 8


For Each oParam As UserParameter In oDoc.componentdefinition.Parameters.UserParameters
oParam.Delete

 Or if you want to target all of the parameters you can use 

'Loop Document and target all parameters
For Each oParam As Inventor.Parameter In oDoc.ComponentDefinition.Parameters
oParam.Delete
Next

 

Error in Targeting a User Parameter collection as a Parameter Object

AAcheson_0-1630468269081.png

As you can see if your in the wrong collection or haven't declared the object correctly, Delete is not available to you.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 13 of 17

didin.suryadi6JREK
Advocate
Advocate

Hi,

 

I really dont know how to solve this, When i saved the codes was working. But when it ran shows the error msg:

 

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.Parameter.Delete()
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
Message 14 of 17

A.Acheson
Mentor
Mentor

I would suggest step through the code with a message box and switch of section of code where you think error might have occurred. It looks like parameter is being mentioned in the error message. Perhaps an error trap is needed in that area. I will be able to take a look at this tomorrow. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 15 of 17

A.Acheson
Mentor
Mentor
Accepted solution

Here is the rule that works for me, it is ran in an external rule and with Inv 2020

 

 'Declare this document
 Dim doc As Document
 doc = ThisDoc.Document

'Check if we have a part document
If doc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	Dim oDoc As PartDocument
	'Make the document before checking equal to document after checking
		oDoc = doc
	For Each oUserParam As UserParameter In oDoc.ComponentDefinition.Parameters.UserParameters
	oUserParam.Delete
	Next

	Dim oDPComp As DerivedPartComponent
	Dim oDPComps As DerivedPartComponents
	oDPComps = oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents
	
		For x = 1 To oDPComps.Count
			oDPComp = oDPComps.Item(x)
			Dim oDPDef As DerivedPartUniformScaleDef = oDPComp.Definition 
			Dim oDPEnts As DerivedPartEntities = oDPDef.Parameters
			Dim oDPEnt As DerivedPartEntity
				'Loop to include/exclude parameters
				For Each oDPEnt In oDPEnts
					'Filter for specific parameter
					'If oDPEnt.ReferencedEntity.Name = "Length" Then ' Add your parameter name here!
						oDPEnt.IncludeEntity = True 'True to include, False to exclude!
						'Exit For
					'End If
				Next
			oDPComp.Definition = oDPDef
		Next

	'Next 'Derived part componen

	'define custom property collection
	Dim customPropertySet As PropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")
	'look at each property in the collection
	For Each oCustProp In customPropertySet
	'delete the custom iProperty
	oCustProp.Delete

	Next

	Dim propertyName1 As String = "Rev Notes"
	Dim propertyValue1 As String = ""

	Try
		prop = customPropertySet.Item(propertyName1)
	Catch
		customPropertySet.Add("", propertyName1)
	End Try

	Dim propertyName2 As String = "Revision Date"
	Dim propertyValue2 As Nullable(Of Date) = Date.Now
	Dim NullDate As Nullable(Of Date)
	Try
		prop = customPropertySet.Item(propertyName2)
	Catch
		customPropertySet.Add(propertyValue2, propertyName2)
	    iProperties.Value("Custom", propertyName2) = NullDate	
	End Try

	Dim propertyName3 As String = "Bending Proficient"
	Dim valString As String = InputBox("Salvagnini Proficient:", "Set Property", "No")
	Dim propertyValue3 As Boolean = If (valString = "Yes", True, False)
	Try
		prop = customPropertySet.Item(propertyName3)
	Catch
		prop = customPropertySet.Add(propertyValue3, propertyName3)
	End Try

	iProperties.Value("Custom", propertyName3) = propertyValue3

	Dim propertyName4 As String = "ECN_DATE"
	Dim propertyValue4 As Nullable(Of Date) = Date.Now
	Try
		prop = customPropertySet.Item(propertyName4)
	Catch
		customPropertySet.Add(propertyValue4, propertyName4)
		iProperties.Value("Custom", propertyName4) = NullDate	
	End Try

	Dim propertyName5 As String = "ECN_ENGINEER"
	Dim propertyValue5 As String = ""


	Try
		prop = customPropertySet.Item(propertyName5)
	Catch
		customPropertySet.Add(propertyValue5, propertyName5)
	End Try


	Dim propertyName6 As String = "ECN_NUMBER"
	Dim propertyValue6 As String = ""
	Try
		prop = customPropertySet.Item(propertyName6)
	Catch
		customPropertySet.Add(propertyValue6, propertyName6)

	End Try

	Dim propertyName7 As String = "GRAIN_LENGTH"
	Dim propertyValue7 As String = "=<Sheet Metal Length>"
	Try
		prop = customPropertySet.Item(propertyName7)
	Catch
		customPropertySet.Add(propertyValue7, propertyName7)

	End Try

	Dim propertyName8 As String = "GRAIN_WIDTH"
	Dim propertyValue8 As String = "=<Sheet Metal Width>"
	Try
		prop = customPropertySet.Item(propertyName8)
	Catch
		customPropertySet.Add(propertyValue8, propertyName8)

	End Try


	Dim oUM As UnitsOfMeasure = oDoc.UnitsOfMeasure
	Dim oLengthUnits As String = InputBox("Length units:", "Masukan Unit Length", oUM.GetStringFromType(oUM.LengthUnits))
	Try
		oUM.LengthUnits = oUM.GetTypeFromString(oLengthUnits)
	Catch
		MessageBox.Show("""" & oLengthUnits & """"& " is not a valid length units", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
	End Try

	Dim oMassUnits As String = InputBox("Mass units:", "Masukan Unit Massa", oUM.GetStringFromType(oUM.MassUnits))
	Try
		oUM.MassUnits = oUM.GetTypeFromString(oMassUnits)
	Catch
		MessageBox.Show("""" & oMassUnits & """"& " is not a valid mass units", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
	End Try


	Dim oMaterials As New List(Of String)
	Dim oActiveMaterial As String = oDoc.ActiveMaterial.DisplayName
	For Each oMaterial As MaterialAsset In ThisApplication.ActiveMaterialLibrary.MaterialAssets
		oMaterials.Add(oMaterial.DisplayName)
	Next
	If oMaterials.Contains(oActiveMaterial) = False Then oMaterials.Add(oActiveMaterial)

	oMaterials.Sort
	Dim selectedMaterial As String = InputListBox("Pilih material", oMaterials, oActiveMaterial)
	Try
	oDoc.ActiveMaterial = ThisApplication.ActiveMaterialLibrary.MaterialAssets.Item(selectedMaterial)
	Catch
	End Try

	iProperties.Value("Summary", "Author") = ThisApplication.UserName
	iProperties.Value("Project", "Revision Number") = InputBox("Revision Number:", "Set Property", "-")
	iProperties.Value("Project", "Designer") = ThisApplication.UserName
	iProperties.Value("Project", "Engineer") = ThisApplication.UserName
	iProperties.Value("Project", "Creation Date") = Today
	ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd").Execute
	myMass = iProperties.Mass

	MessageBox.Show("Mass = " & myMass, "iLogic")

Else
	
	'*** Insert  stuff here
	MessageBox.Show("This is not a Part Exiting!", "Title")

End If

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 16 of 17

didin.suryadi6JREK
Advocate
Advocate

Waw..

 

Thank You very much, Now is working.

 

 

0 Likes
Message 17 of 17

A.Acheson
Mentor
Mentor

Glad to hear it’s working👍Only a few minor tweaks were needed. A good learning exercise. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes