Change length of a line in sketch environment

Change length of a line in sketch environment

piotrekdoro94
Advocate Advocate
711 Views
3 Replies
Message 1 of 4

Change length of a line in sketch environment

piotrekdoro94
Advocate
Advocate

Hi, I'm having problems trying to do a seemingly basic action. I have a sketch on my base view that is completely constrained aside from the length of the blue line. It looks like this:

 

Untitled.png

 

Essentially I can't find an efficient way of setting the length of the blue line.

 

- length property is read only

- can't find documentation on the scale command in sketch environment (I could just scale it by 44.671/5)

- I thought I could just add a dimension , then set its value and let the inventor's constraint solver do the rest but I'm not sure if that's the case 

 

I simply want to change the length of a line so that the dimension 44.671 becomes 5.6. What I did  was, I've calculated a scale factor (44.617/5.6) and then multiplied it by the difference in X and Y coordinates between line's start and end point to get new endpoint coordinates and then I've moved endpoint of my line to those coordinates. Only afterwards, when the line was already the right length did I add a dimensional constraint. Alternatively I could probably move it with a vector2d bbut that would be even more hassle.

0 Likes
Accepted solutions (1)
712 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Hi @piotrekdoro94.  If you are wanting to change/control its length entirely by code, then you should place a DimensionConstraint on it (DimensionConstraints.AddTwoPointDistance), capture that DimensionConstraint to a variable when you create it.  Then you can access its DimensionConstraint.Parameter property to access the Parameter that gets automatically created with it.  Then you can either just check its name, or change its name.  Then later, if you want to change the length of that line, either just change the value of that parameter directly, or iterate through all DimensionConstraints of that sketch again, checking its Parameter property, and checking the parameter's name, until you find that one again, then change its value that way.  Keep in mind though, when dealing with an Inventor API Parameter object directly, its Value & ModelValue are both set and retrieved in 'database units' (centimeters for distance), not necessarily document units, or the parameter's own units.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

piotrekdoro94
Advocate
Advocate

Thank you for help, it seems that I’ve read the documentation wrong. I’ve looked at DimensionConstraint.Parameter, noticed that it’s read only and didn’t try to interact with it further, but actually even though it is read only it returns a reference to a parameter which can be changed.

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Yep.  That is a very common misconception that I, and many others had, on multiple occasions.  There are a lot of cases like that too.  When a property says it is ReadOnly, and its 'value Type' is a basic data type, like Integer, Double, or String, then you will not be able to change it directly through that property, but sometimes there will be a 'method' (Sub or Function) that is used to 'set' it's value.  But if a property is ReadOnly and its 'value Type' is a type of Object (Parameter, Feature, Sketch, Document, etc), then that usually just means that you can not set another Object (Parameter, Feature, Sketch, Document, etc) as its value directly, but does not always necessarily mean that we can not make changes to the properties of that Object.  Whether this will be possible or not depends on the type of Object, and how that object's property values are managed behind the scenes, within the supporting source code for that Type.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes