Determining Scale on a sketch in a Drawing document

Determining Scale on a sketch in a Drawing document

Qube-it
Advocate Advocate
838 Views
7 Replies
Message 1 of 8

Determining Scale on a sketch in a Drawing document

Qube-it
Advocate
Advocate
I'm adding a center point rectangle tool to the sketch environment and that includes drawing sketches. The problem I'm having is when dealing with the sketches in Drawing Documents that are not a 1:1 scale. The rectangle is created interactively (just like the regular Inventor Rectangle) with the location of the user's mouse movements determing the size of the rectangle.

When there is a scale that's less than a 1:1 ratio, the rectangle obviously is generated smaller than normal. I understand the why of this problem, but I'm not quite sure how to scale the rectangle accordingly.

BTW, it's late for me and I'm practically falling asleep writing this, so if it doesn't make any sense, let me know.

-Brian Hall-
-Brian Hall-
0 Likes
839 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
I don't understand why scale is involved. A rectanlge has height and width.
0 Likes
Message 3 of 8

Qube-it
Advocate
Advocate
Allow me to further explain the problem.

When the user activates the Center Point Rectangle command, I subscribe to the OnMouseClick event to see where the user clicks in the drawing document sketch. Let's say the scale is 1/4" = 1'-0" (A.K.A. 1:48) and the user clicks in the middle of the sheet to create the rectangle. Currently, the rectangle gets created at a 1:48 scale which actually puts the rectangle way down over in the lower left corner of the sheet. This is because of the following:

I programatically create the rectangle by using the X and Y properties of the "modelPosition" parameter in the OnMouseClick events arguments to locate the center of the rectangle and then as the user drags the mouse around I am using the OnMouseMove event to dyamically change the size of the rectangle relative to the center point. Again, I'm using the X and Y properties of the "modelPosition" parameter in the OnMouseMove event's arguments to determine one corner of the rectangle and then mathematically creating the other three point coordinates to maintain the size of the rectangle. Does that make any sense?

Since the drawing is at a 1:48 scale the model point coordinates that are passed in from the OnMouseClick and OnMouseMove events are being "reduced" (for lack of a better term) by the same margin and thus creates a very tiny rectangle in a coordinate location relative to the sheet position that the user clicked in to begin with. In other words, when the user clicks in the middle of, say, an 11x17 sheet that "true" X,Y coordinate is ~(5.5, 8.5) which then is what is passed into my mouse event handlers. Then the scale of the sketch is somehow applied and the rectangle is reduced accordingly.

I'm having a hard time articulating this, so I might just post a video link if there is still trouble understanding my dillema.

Basically, the root of my question is this: Is there a property for scale that I'm missing that I can use to revert (or scale back up) the coordinates mathematically? Or, is there a method that I call to do this automagically through the API?

-Brian Hall-
-Brian Hall-
0 Likes
Message 4 of 8

Anonymous
Not applicable
Why don't you make the video and perhaps share some code (rectangle calculations).
0 Likes
Message 5 of 8

Qube-it
Advocate
Advocate
Yes, I'll do just that. After reading what I wrote, I'm confused.

-Brian Hall-
-Brian Hall-
0 Likes
Message 6 of 8

Qube-it
Advocate
Advocate
Well, I figured out what the problem was. I went ahead and made the video and posted it to YouTube to explain. Here's the link

http://www.youtube.com/watch?v=MFli0l1oS24

-Brian Hall-
-Brian Hall-
0 Likes
Message 7 of 8

Anonymous
Not applicable
Unfortunately my company blocks youtube and all other social networking sites!
0 Likes
Message 8 of 8

Qube-it
Advocate
Advocate
Well then I guess you'll have to watch it when you get home. 😉

Seriously, though, my problem boiled down to how I was handling the OnMouseClick event. I needed to leverage the point where the user clicks with which to base my rectangle creation. Basically the OnMouseClick event passes in several arguments of which one is called "modelPosition" and it's type is "Point". Inside of a PlanarSketch (editing a sketch inside a part or assembly document) I am able to pass the "modelPosition" argument directly into the PlanarSketch.ModelToSketchSpace method which translates the point for me.

Well, a DrawingSketch object doesn't contain a ModelToSketchSpace method. It does, however, contain a SheetToSketchSpace method which requires a Point2d object be passed into it. At the initial time of this posting, I wasn't firing on all brain synapses and glazed right over the SheetToSketchSpace method and instead tried passing the modelPosition.X and modelPosition.Y properties directly into my private Point2D objects' own X and Y properties respectively. Of course this meant that there was no translation on those coordinates and thus when the scale of the sketch (or user created Draft View) changed so did the location and size of the rectangle.

What I did to fix it was create a temporary Point2d object (local to the event handling method) and passed in the X and Y properties of the modelPosition argument to that temporary Point2d object. Then I called the SheetToSketchSpace method and passed in the temporary Point2d object.

The video shows this much better than I can explain here though.

-Brian Hall-
-Brian Hall-
0 Likes