iLogic setting dimensions driven or not

iLogic setting dimensions driven or not

Anonymous
Not applicable
832 Views
4 Replies
Message 1 of 5

iLogic setting dimensions driven or not

Anonymous
Not applicable

I'm trying to switch between two sets of dimensions being driven or not by using iLogic, but I'm having a bit of a weird issue.

One of the dimensions I named "leaningAngle", and the code looks like this:

 

SyntaxEditor Code Snippet

Dim oDoc as PartDocument
oDoc = ThisDoc.Document

Dim oSketch1 As Sketch

oSketch1 = oDoc.ComponentDefinition.Sketches.Item("Sketch1")

If choice = "Choice1" Then
    oSketch1.DimensionConstraints.Item(leaningAngle).Driven = False
ElseIf choice = "Choice2" Then
    oSketch1.DimensionConstraints.Item(leaningAngle).Driven = True
End If

The weird thing to me about this is that when I change the choice variable to trigger the if statements, its not leaningAngle that changes to driven (or not), but another dimension in the same sketch thats called "d87" and is a hole diameter. So I'm thinking that I need another reference to the leaningAngle dimension, as the name doesn't seem to work, but how do I do that?

0 Likes
833 Views
4 Replies
Replies (4)
Message 2 of 5

dean.morrison
Advocate
Advocate
Hi,
I believe if you reference something by name it must be within "" just like when you reference sketch1 earlier in your code..
oSketch1 = oDoc.ComponentDefinition.Sketches.Item("Sketch1")
oSketch1.DimensionConstraints.Item("leaningAngle").Driven = True
I hope this fixes your issue.
Dean.

 

 

0 Likes
Message 3 of 5

Anonymous
Not applicable

It doesn't seem to work that way, I get an error:

Error in rule: DrivenTest, in document: test.ipt
Conversion from string "leaningAngle" to type 'Integer' is not valid.

The code looks just like in my first post, just with "" around leaningAngle.

0 Likes
Message 4 of 5

Sschram
Enthusiast
Enthusiast

Take off the "" around the parameter you're trying to use.

 

 

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 995 StartFragment: 314 EndFragment: 963 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

oSketch2.DimensionConstraints.Item(WeldCapLength).Driven = True
0 Likes
Message 5 of 5

rjay75
Collaborator
Collaborator

oSketch1.DimensionConstraints.Item(?) requires an integer representing the index of the dimension. That could change as dimensions are added or removed from the sketch. So you could search for the dimension then modifiy it.

 

Dim oDoc as PartDocument
oDoc = ThisDoc.Document

Dim oSketch1 As Sketch

oSketch1 = oDoc.ComponentDefinition.Sketches.Item("Sketch1")

'Loop through dimensions looking for the one named leaningAngle

For Each cDim as DimensionConstraint In oSketch1.DimensionConstraints
   If cDim.Parameter.Name = "leaningAngle" Then
     If choice = "Choice1" Then
         cDim.Driven = False
     ElseIf choice = "Choice2" Then
         cDim.Driven = True
     End If
     'Dimension changed stop looping
     Exit For
   End If
Next

 

In your previous attempt it was looking up value of leaningAngle and using that to pick the dimension at the index of that value in the DimensionConstraints.