Can not create sketchline with API

Can not create sketchline with API

Anonymous
Not applicable
296 Views
2 Replies
Message 1 of 3

Can not create sketchline with API

Anonymous
Not applicable

Hello, I don't know why I can not create a sketchline with a simple VBA programe showd below, I thouht the program statement is very easy,but it's always running fail- can not get any sketch line in active sketch view. Please tell me the reason about it. Your help will be appreciated.

 

Sub test2()
Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument


If Not TypeOf ThisApplication.ActiveEditObject Is sketch Then
    MsgBox "Please run it in the sketch environment."
Exit Sub
End If


Dim oSketch As DrawingSketch
Set oSketch = ThisApplication.ActiveEditObject

 

Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry


Call oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(-4.2, -0.33), oTG.CreatePoint2d(-4.2, -0.225))

End Sub

 

0 Likes
297 Views
2 Replies
Replies (2)
Message 2 of 3

ekinsb
Alumni
Alumni

I think your program is working it's just that the results might not be what you're looking for so you didn't see the line.  Here are a couple of things to remember when working with sketches in a drawing.  If the sketch is created on sheet, then the origin of the sketch is the lower-left hand corner of the sheet.  This is what I did when I tested your program and the line is off of the sheet so I had to zoom out to be able to see it.

 

If you create a sketch on a drawing view then the origin of the sketch is at the center of the drawing view.

 

The coordinates are in centimeters.  In your case, the line being created is quite small and easy to overlook.  I ended up zooming out so I could see a large area around the sheet and then used the select area (click and drag the mouse) to select everything in the view and then it became obvious where the line was.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 3

Anonymous
Not applicable

Thanks very much Brian, yes you are right, the program is working, the sketch line is just hided from the Centermaked line, their color is too close to differentiate it. How stupid I am.

By the way , I found a very strange problem on my Inventor VBA, could you help me to explain the reason for below link:

http://forums.autodesk.com/t5/inventor-customization/sketchline-sketch-is-lower-case-letter/td-p/571...

 

Thanks a lot.

0 Likes