Message 1 of 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello every one, I whant to make the dimension below (Lato L) driven using iLogic
Solved! Go to Solution.
Hello every one, I whant to make the dimension below (Lato L) driven using iLogic
Solved! Go to Solution.
Hi @JonnyPot. Here is something you can use for that. This example just uses the Pick method to allow you to select the dimension, but the main point of this example is showing you how the property of the DimensionConstraint object called Driven can be used to toggle that setting you want to control.
oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchDimConstraintFilter, oPrompt)
If IsNothing(oObj) OrElse (TypeOf oObj Is DimensionConstraint = False) Then Exit Sub
Dim oDimC As DimensionConstraint = oObj
If Not oDimC.Driven Then oDimC.Driven = True
Wesley Crihfield
(Not an Autodesk Employee)
Hello, thank you for the replay. is it possible to make it so that i dont have to pick the dimension, for example a rule that when run it only transforms a dimension into a driven dimension, i tried making it as follows but i keep getting "Type 'DimensionConstraint.Driven' is not defined."
Dim LatoA1 As DimensionConstraint.Driven = LatoA If Not LatoA1.Driven Then LatoA1.Driven = True
Sure. You don't have to use the Pick method to specify which dimension to target. There are certainly other ways, but since I'm not familiar with your existing design document, and don't even know if it is a part or an assembly, I have no way of knowing which dimension within which sketch to find using normal means. And I don't know what 'LotaA' represents in the code you posted. But I do know that you shouldn't have the ".Driven" part at the end of "As DrawingDimension.Driven"...it should just by "As DrawingDimension" because that is the object Type. Driven is a Property of that DrawingDimension object that represents a Boolean value. If the sketch is 'active' or in 'edit mode' when you run the rule, I could capture that sketch using the term 'ThisApplication.ActiveEditObject', but if that's not the case, I will just try to get the last sketch that was created within the active model document. Then once I have a sketch to target, I will attempt to identify a single dimensional constraint within that sketch, and hope that it's the right one. If the first dimension is not the right one, then we will have to find another way to identify the correct dimension without manually selecting it.
Here is my new example code for you to try out.
Dim oSketch As PlanarSketch = Nothing
If TypeOf ThisApplication.ActiveEditObject Is PlanarSketch Then
oSketch = ThisApplication.ActiveEditObject
Else
Dim oSketches As PlanarSketches = ThisDoc.Document.ComponentDefinition.Sketches
oSketch = oSketches.Item(oSketches.Count) 'the last sketch created
End If
Dim oDimConst As DimensionConstraint = oSketch.DimensionConstraints.Item(1)
If Not oDimConst.Driven Then oDimConst.Driven = True
Wesley Crihfield
(Not an Autodesk Employee)
hi, my sketch (named Perimeter) its in a assembly, and i would like to make the dimension "Length_A" driven
OK. I was able to open your model and see the sketch & dimensions. Although the referenced components didn't load correctly, I was able to quickly create a simple iLogic rule that will do the task.
Dim oADoc As AssemblyDocument = ThisDoc.Document
oSketch = oADoc.ComponentDefinition.Sketches.Item("Perimeter")
For Each oDim As DimensionConstraint In oSketch.DimensionConstraints
If oDim.Parameter.Name = "Length_A" Then
If Not oDim.Driven Then
oDim.Driven = True
End If
End If
Next
The rule immediately changed the status of the dimension from 'driving' to 'driven', without the sketch even needing to be in 'edit mode'. Since we know the name of the sketch, and that the sketch was created within the context of the main assembly, I just got the sketch by its name. Then to find the right dimensional constraint within the sketch, I simply looped through all the dimensional constraints within the sketch, checking the name of the Parameter it is tied to for "Length_A". When found, simply change its Driven property's value to True.
Wesley Crihfield
(Not an Autodesk Employee)
i created a rule with the code that you gave me but it doesn't convert Length_A into a driven dimension. When i run it and the dimension Length_A is not driven it does nothing, but when Length_A is driven the rule conferts it into a non driven rule.
I attached the file that i used, the ruler's name is Length_A
Hi @JonnyPot. I opened new top level assembly in your latest zip file. At first, sketch dimension using the "Length_A" parameter did not have the "(" and ")" symbols around its name. That means it is currently 'driving' (in control of) the geometry. When I enter into edit mode of the sketch, then right click on that dimension, I have the option in my radial menu to turn it into a 'driven' (not in control / reference only) dimension.
When I choose that option, the name of the dimension changes, and now shows the "(" and ")" around its name, indicating that it is now a 'driven' dimension.
Then if I right click on that dimension again, that option shows up in my radial menu again, but this time it already has a check mark in it, meaning that the dimension is already 'driven', so choosing this option again will toggle that setting off, making the dimension 'driven' again.
When the dimension looks like this:
before I run the rule, then I run the rule you have there named "Length_A", it changes that dimension to looking like this:
When it has those "(" and ")" around its name, the dimension is then a 'driven' dimension. That's why when you get the DimensionConstraint object in the API, it has that Property called "Driven", and its value is a Boolean (True/False). When the value of that property is set to True, that means the dimension is driven. When its value is False, it is not driven. Well, the code was designed to make sure the value of that Driven property of that dimension gets set to True, and it appears to be doing its job OK to me.
If you would rather have the code simply 'toggle' its value, instead of always set it to True, that can easily be done too, by replacing this:
If Not oDim.Driven Then
oDim.Driven = True
End If
with this:
oDim.Driven = Not oDim.Driven
Then, if the dimension is currently driving, running the rule will toggle it to driven, and if the dimension is currently driven, running the rule will toggle it to driving.
Wesley Crihfield
(Not an Autodesk Employee)