How to set mate/Parameter conditions when a view representation is set Using ilogic.

How to set mate/Parameter conditions when a view representation is set Using ilogic.

arnold.ogalo
Contributor Contributor
1,296 Views
5 Replies
Message 1 of 6

How to set mate/Parameter conditions when a view representation is set Using ilogic.

arnold.ogalo
Contributor
Contributor

Hello,

I am new to ilogic, and I am trying to set conditions when a view representation is selected. 

 

for instance when I select Closed view representation from the assembly tree, how can I specify the value(d342) of a  mate and the value of the parameter RH. This is my code so far. 

 

Dim doc As AssemblyDocument = ThisDoc.Document
Dim oAsmCompDef As ComponentDefinition
Dim oViewReps As DesignViewRepresentation
oViewReps = oAsmCompDef.RepresentationsManager.DesignViewRepresentations

If	oViewReps.Activate = "Closed" Then 'Closed is a view representation name
	Parameter("SM50184_003:1", "RH") = 400   'These are the parameters to manually change. 
	d342 = 535.000 mm
Else
	d342 = 735.000 mm
	Parameter("SM50184_003:1", "RH") = 300
	
End If

ThisApplication.ActiveView.Fit
iLogicVb.UpdateWhenDone = True

 

0 Likes
1,297 Views
5 Replies
Replies (5)
Message 2 of 6

johnsonshiue
Community Manager
Community Manager

Hi Arnold,

 

I believe there is a logical error here. The condition of oViewReps.Activate = "Closed" means that Design View will be activated. Instead, you should use oViewReps.Name = "Closed", which means that the currently activated DV is "Closed."

Many thanks!



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
0 Likes
Message 3 of 6

arnold.ogalo
Contributor
Contributor

Thanks for the reply I changed the code as suggested. However inventor returned the error of [Object Variable or with Block variable not set.]

Could the problem be with how I defined the variables or is something missing. 

0 Likes
Message 4 of 6

A.Acheson
Mentor
Mentor

The issue is this line

Dim oAsmCompDef As ComponentDefinition

You have declared the component definition albeit not specifically an assembly component definition but not set the document to the component definition. 

Dim doc As AssemblyDocument = ThisDoc.Document

Dim
oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = doc.ComponentDefinition

 

 

 

 

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

WCrihfield
Mentor
Mentor

Here is a corrected and complete version of your code.  Although, it may still encounter errors if those specified parameters aren't found within those specified components, or if those values are out of range.  Keep in mind that any plain numbers you use within the iLogic rule environment that represent measurements are understood as 'database units' (centimeters for length), instead of whatever units you may be using within your document.

 

Dim doc As AssemblyDocument = ThisDoc.Document
Dim oAsmCompDef As AssemblyComponentDefinition = doc.ComponentDefinition
Dim oViewReps As DesignViewRepresentations = oAsmCompDef.RepresentationsManager.DesignViewRepresentations
If	oAsmCompDef.RepresentationsManager.ActiveDesignViewRepresentation Is oViewReps.Item("Closed") Then 'Closed is a view representation name
	Parameter("SM50184_003:1", "RH") = 400   'These are the parameters to manually change. 
	d342 = 535.000 mm
Else
	d342 = 735.000 mm
	Parameter("SM50184_003:1", "RH") = 300
End If
ThisApplication.ActiveView.Fit
iLogicVb.DocumentUpdate

 

 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)

0 Likes
Message 6 of 6

arnold.ogalo
Contributor
Contributor

So this is my final code. I wasn't able to make the rule run when the view representation is changed and so I made a user parameter. So this is my final code.

Thank you all for the help. 

'Defining the Assembly variables
Dim doc As AssemblyDocument = ThisDoc.Document
Dim oAsmCompDef As AssemblyComponentDefinition
'Defining the View Variables
oAsmCompDef = doc.ComponentDefinition
Dim oViewReps As DesignViewRepresentations = oAsmCompDef.RepresentationsManager.DesignViewRepresentations

'Activate  viewrep via parameter selected 
oViewReps.Item(ViewRep).Activate

'Conditions for View Representations
If  oAsmCompDef.RepresentationsManager.ActiveDesignViewRepresentation Is oViewReps.Item("Home") Then
	'Closed is a view representation for the closed position
	Parameter("SM50184_003:1", "RH") = 525 mm
	d346 = 0.00 deg
ElseIf oAsmCompDef.RepresentationsManager.ActiveDesignViewRepresentation Is oViewReps.Item("Default") Then
	Parameter("SM50184_003:1", "RH") = 133 mm
	d346 = 0.00 deg
ElseIf oAsmCompDef.RepresentationsManager.ActiveDesignViewRepresentation Is oViewReps.Item("Maintenance") Then
	Parameter("SM50184_003:1", "RH") = 713.8 mm
	d346 = -90.00 deg
End If

ThisApplication.ActiveView.Fit
iLogicVb.UpdateWhenDone = True 

 

0 Likes