iLogic- iProperty value according to keyword in other iProperty

iLogic- iProperty value according to keyword in other iProperty

mech_eng
Advocate Advocate
3,034 Views
30 Replies
Message 1 of 31

iLogic- iProperty value according to keyword in other iProperty

mech_eng
Advocate
Advocate

Hello,

 

Is it possible for an iLogic rule in an assembly to do the following:

- check for a each component. for example, in the iProperty Description any keyword, for example, Bolt or Bolt.

- in case a keyword exists, special iProperty value is assigned to other iProperty (i.e., Title) for this component

- in case if there is no such keyword, check the next component ... and so on.

 

Thanks

0 Likes
Accepted solutions (2)
3,035 Views
30 Replies
Replies (30)
Message 21 of 31

marcin_otręba
Advisor
Advisor

hi,

 

what inventor you use ?

I checked and it works for me only odoc must be declared, and material must be present in your library.

 

Dim odoc As PartDocument
For Each oOccurrence In ThisDoc.Document.ComponentDefinition.Occurrences
odoc=oOccurrence.Definition.Document
If odoc.PropertySets(3).Item("Description").Value.ToString.ToLower.Contains(my_prop_val.ToLower) Then
iProperties.Value(oOccurrence.Name, "Summary", "Title") = GoExcel.CellValue("B" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Title_En") = GoExcel.CellValue("C" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Title_Lt") = GoExcel.CellValue("D" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Title_Ru") = GoExcel.CellValue("E" & MyRow)
Dim assetLib As AssetLibrary
Dim libAsset As Asset
assetLib = ThisApplication.AssetLibraries.Item("Materialy")
Try
	odoc.ComponentDefinition.Material = odoc.Materials.Item(GoExcel.CellValue("L" & MyRow))
Catch
		Try
		libAsset = assetLib.MaterialAssets.ItemGoExcel.CellValue("L" & MyRow))
		libAsset.CopyTo(odoc, True)
		odoc.ComponentDefinition.Material = odoc.Materials.Item(GoExcel.CellValue("L" & MyRow))
Catch End Try End Try Try odoc.ActiveAppearance=odoc.AppearanceAssets.Item(GoExcel.CellValue("P" & MyRow)) Catch Try libAsset = assetLib.AppearanceAssets.Item(GoExcel.CellValue("P" & MyRow)) libAsset.CopyTo(odoc, True) odoc.ActiveAppearance=odoc.AppearanceAssets.Item(GoExcel.CellValue("P" & MyRow)) Catch End Try End Try End If Next   

 

Hi, maybe you want to vote my:

Ideas

or check my apps:

DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 22 of 31

mech_eng
Advocate
Advocate

Hello,

I am using Inventor Pro 2012

0 Likes
Message 23 of 31

marcin_otręba
Advisor
Advisor

Try this:

 

Dim odoc As PartDocument
For Each oOccurrence In ThisDoc.Document.ComponentDefinition.Occurrences
odoc=oOccurrence.Definition.Document
If odoc.PropertySets(3).Item("Description").Value.ToString.ToLower.Contains(my_prop_val.ToLower) Then
iProperties.Value(oOccurrence.Name, "Summary", "Title") = GoExcel.CellValue("B" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Title_En") = GoExcel.CellValue("C" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Title_Lt") = GoExcel.CellValue("D" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Title_Ru") = GoExcel.CellValue("E" & MyRow)
odoc.iproperties.material=GoExcel.CellValue("L" & MyRow)
odoc.iproperties.PartColor=GoExcel.CellValue("P" & MyRow)
	End If 
Next 

 

Hi, maybe you want to vote my:

Ideas

or check my apps:

DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 24 of 31

mech_eng
Advocate
Advocate

Error Mesage:

 

System.MissingMemberException: Common member "iproperties" for type "PartDocument" not found.
at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
Message 25 of 31

marcin_otręba
Advisor
Advisor

sorry i do not have 2012 and i do not remember how it was , but you can try last one:

 

Dim odoc As PartDocument
For Each oOccurrence In ThisDoc.Document.ComponentDefinition.Occurrences
odoc=oOccurrence.Definition.Document
If odoc.PropertySets(3).Item("Description").Value.ToString.ToLower.Contains(my_prop_val.ToLower) Then
iProperties.Value(oOccurrence.Name, "Summary", "Title") = GoExcel.CellValue("B" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Title_En") = GoExcel.CellValue("C" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Title_Lt") = GoExcel.CellValue("D" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Title_Ru") = GoExcel.CellValue("E" & MyRow)
odoc=ThisApplication.Documents.Open(odoc=oOccurrence.Definition.Document.fullfilename,True)
iProperties.Material = GoExcel.CellValue("L" & MyRow)
iProperties.PartColor=GoExcel.CellValue("P" & MyRow)
odoc.save
odoc.close(True)

End If 
Next 

It will open part document and change material and color in it.

Hi, maybe you want to vote my:

Ideas

or check my apps:

DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 26 of 31

mech_eng
Advocate
Advocate

Error message:

(Sorry but the text on my machine in row System.NullRef... is appear in Russian and I have translated it)

 

System.NullReferenceException: Oblect variable or block With variable is not defined

(Не задана переменная объекта или переменная блока With).
at Microsoft.VisualBasic.CompilerServices.Symbols.Container..ctor(Object Instance)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
Message 27 of 31

mech_eng
Advocate
Advocate

Instead

odoc=oOccurrence.Definition.Document

Should be

odoc.oOccurrence.Definition.Document

And instead

odoc=ThisApplication.Documents.Open(odoc=oOccurrence.Definition.Document.fullfilename,True)

Should be

odoc.ThisApplication.Documents.Open(odoc=oOccurrence.Definition.Document.fullfilename,True)

 ?

0 Likes
Message 28 of 31

marcin_otręba
Advisor
Advisor

sorry,

 

instead of :

 

odoc=ThisApplication.Documents.Open(odoc=oOccurrence.Definition.Document.fullfilename,True)

should be

odoc=ThisApplication.Documents.Open(oOccurrence.Definition.Document.fullfilename,True)

 

could you place here your full code ?

Hi, maybe you want to vote my:

Ideas

or check my apps:

DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 29 of 31

mech_eng
Advocate
Advocate

Hello,

 

Full code:

Dim odoc As PartDocument
Dim oProject As DesignProject  
oProject = ThisApplication.DesignProjectManager.ActiveDesignProject 

Dim oName As String 
oName = oProject.Name 

oName = "\" + oName + ".ipj"
Dim my_prop_val As String
Dim oProjectPath As String 
oProjectPath = oProject.FullFileName 

Dim oPath As String 
oPath = oProjectPath.Replace (oName, "") 

GoExcel.Open(oPath & "\_iLogic\iLogic_iProp.xlsx", "Fasteners")
'Open Excel file'

MyRow = InputBox("Specify the type:" & vbCrLf & _
"2 - Bolt" & vbCrLf & _
"3 - Screw" & vbCrLf & _
"4 - Nut" & vbCrLf & _
"5 - Washer", "Import Row", "2")
Select Case MyRow
	Case "2"
	my_prop_val = "Bolt"
	Case "3"
	my_prop_val = "Screw"
	Case "4"
	my_prop_val = "Nut"
	Case "5"
	my_prop_val = "Washer"
End Select
'Prompt User To Choose row To read In,
'Get the iProperty from selected Row For Each column
Dim oOccurrence As ComponentOccurrence

For Each oOccurrence In ThisDoc.Document.ComponentDefinition.Occurrences
odoc.oOccurrence.Definition.Document

If odoc.PropertySets(3).Item("Description").Value.ToString.ToLower.Contains(my_prop_val.ToLower) Then
iProperties.Value(oOccurrence.Name, "Summary", "Title") = GoExcel.CellValue("B" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Title_En") = GoExcel.CellValue("C" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Title_Lt") = GoExcel.CellValue("D" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Title_Ru") = GoExcel.CellValue("E" & MyRow)
iProperties.Value(oOccurrence.Name, "Project", "Stock Number") = GoExcel.CellValue("F" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Material_Shape_En") = GoExcel.CellValue("G" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Material_Shape_Lt") = GoExcel.CellValue("H" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Material_Shape_Ru") = GoExcel.CellValue("I" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Material_Certificate_Norm") = GoExcel.CellValue("J" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Material_Certificate_Type") = GoExcel.CellValue("K" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Material_Full") = GoExcel.CellValue("L" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Material_Dim_d") = GoExcel.CellValue("M" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Material_Dim_L") = GoExcel.CellValue("N" & MyRow)

odoc=ThisApplication.Documents.Open(odoc.oOccurrence.Definition.Document.fullfilename,True)
iProperties.Material = GoExcel.CellValue("L" & MyRow)
iProperties.PartColor = GoExcel.CellValue("P" & MyRow)
odoc.Save
odoc.Close(True)

End If

Next

Then, error message:

System.NullReferenceException: The variable of object or the variable of block With is not defined (Не задана переменная объекта или переменная блока With).
at Microsoft.VisualBasic.CompilerServices.Symbols.Container..ctor(Object Instance)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

Ragards

0 Likes
Message 30 of 31

marcin_otręba
Advisor
Advisor
Accepted solution

You didin't correct line wchich i wrote.

Corrected code:

 

 

Dim odoc As PartDocument
Dim oass As AssemblyDocument=ThisDoc.Document
Dim oProject As DesignProject  
oProject = ThisApplication.DesignProjectManager.ActiveDesignProject 

Dim oName As String 
oName = oProject.Name 

oName = "\" + oName + ".ipj"
Dim my_prop_val As String
Dim oProjectPath As String 
oProjectPath = oProject.FullFileName 

Dim oPath As String 
oPath = oProjectPath.Replace (oName, "") 



'Open Excel file'

MyRow = InputBox("Specify the type:" & vbCrLf & _
"2 - Bolt" & vbCrLf & _
"3 - Screw" & vbCrLf & _
"4 - Nut" & vbCrLf & _
"5 - Washer", "Import Row", "2")
Select Case MyRow
	Case "2"
	my_prop_val = "Bolt"
	Case "3"
	my_prop_val = "Screw"
	Case "4"
	my_prop_val = "Nut"
	Case "5"
	my_prop_val = "Washer"
End Select
'Prompt User To Choose row To read In,
'Get the iProperty from selected Row For Each column
Dim oOccurrence As ComponentOccurrence
GoExcel.Open( "C:\Vault\_iLogic\iLogic_iProp.xlsx", "Fasteners")
For Each oOccurrence In oass.ComponentDefinition.Occurrences
If oOccurrence.Definition.Document.PropertySets(3).Item("Description").Value.ToString.ToLower.Contains(my_prop_val.ToLower) Then
	
iProperties.Value(oOccurrence.Name, "Summary", "Title") = GoExcel.CellValue("B" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Title_En") = GoExcel.CellValue("C" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Title_Lt") = GoExcel.CellValue("D" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Title_Ru") = GoExcel.CellValue("E" & MyRow)
iProperties.Value(oOccurrence.Name, "Project", "Stock Number") = GoExcel.CellValue("F" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Material_Shape_En") = GoExcel.CellValue("G" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Material_Shape_Lt") = GoExcel.CellValue("H" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Material_Shape_Ru") = GoExcel.CellValue("I" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Material_Certificate_Norm") = GoExcel.CellValue("J" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Material_Certificate_Type") = GoExcel.CellValue("K" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Material_Full") = GoExcel.CellValue("L" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Material_Dim_d") = GoExcel.CellValue("M" & MyRow)
iProperties.Value(oOccurrence.Name, "Custom", "Material_Dim_L") = GoExcel.CellValue("N" & MyRow)

'odoc=ThisApplication.Documents.Open(oOccurrence.Definition.Document.fullfilename,True)
odoc=oOccurrence.Definition.Document
odoc.componentdefinition.Material = ThisApplication.StylesManager.Materials.Item(GoExcel.CellValue("L" & MyRow))
odoc.ActiveRenderStyle= odoc.RenderStyles.Item(GoExcel.CellValue("P" & MyRow))

iLogicVb.UpdateWhenDone = True	
End If


Next
GoExcel.Close

 

Hi, maybe you want to vote my:

Ideas

or check my apps:

DrawingTools   View&ColoringTools   MRUFolders

Message 31 of 31

mech_eng
Advocate
Advocate

Thank You very much !

It works

0 Likes