OFFSET THRU POINT finally working

OFFSET THRU POINT finally working

Anonymous
Not applicable
416 Views
6 Replies
Message 1 of 7

OFFSET THRU POINT finally working

Anonymous
Not applicable
VBA entity.offset works with a positive or negative distance, but how to figure out the sign?
The normal command-interface is easy: just point which side or (more important) point an entity.
How to simulate this in VBA? Well, run a Lisp-routine.... Easy, yes, but.... each entity has a handle, so you can SendCommand "(setq e (handent " & chr(34) & e.handle & chr(34) & "))" & vbCr , so now you have Lisp-var "e" .
Through a point? This one is tricky, but also stupidly easy: watch the fraction-sign: is it a "." or a "," !! In AC one uses the point-notation as in VBA-strings!!! it is a "," (comma), so clean up with pt(0)=Replace(.coordinates(0),".","") and pt(0)=Replace(pt(0),",","."). Now you can SendCommand "(setq pt (" & pt(0) & " " & pt(1) & " " & pt(2) & "))" & vbCr
Now perform the sendcommand "Offset" & vbCr & "T" & vbCr & e & vbCr & pt & vbCr & vbCr
Don't forget to clean up the lisp-vars: sendcommand "(setq e nil pt nil)"& vbcr
One of the nice things is thjat you can check if a point is "Inside" a circle or close polyline!!
0 Likes
417 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
interesting. but without using send command, one way to determine if a point is inside a closed polyline is to construct a ray from the point and count intersections, if odd than the point is inside if 0 or even then the point is outside the polyline.
0 Likes
Message 3 of 7

Anonymous
Not applicable
hi cadger, I must admit that your suggestion for the "Inside" is far more elegant, but it was a possible offspring of the "offset thru point" routine.
I spent some sleepless nights trying to figure out the AC command "Offset" "T", as far as I got was that I needed to calculate the nearest point on the object to the thru-point, that would be the offset-distance, and subtracting the nearest point off the thru-point would result in an positive or negative distance. The calculator should be able to do this, but couldn't find anything alike in the VBA.
Using LISP (the old guys as I breathe that) is in VBA incredibly fast, and VBA does not cover all the LISP-functionality. Edited by: lucaso on Feb 23, 2009 11:10 AM
0 Likes
Message 4 of 7

Anonymous
Not applicable
Hi cadger,

Any Idea why this only works when tried once, but not as part of a serie of commands, meaning:
checking if a bunch of points are inside a circle or closed polylines?

Public Function Inside (ByRef e As AcadEntity, ByRef pt() As Double) As Boolean
Dim ok As Boolean
ok = False
Dim ray As AcadRay
Dim l As AcadLine
Dim ptx(2) As Double
ptx(0) = pt(0) + 100
ptx(1) = pt(1)
ptx(2) = pt(2)
Dim ins As Variant
If ThisDrawing.ActiveSpace = acModelSpace Then
Set ray = ThisDrawing.ModelSpace.AddRay(pt, ptx)
ins = ray.IntersectWith(e, acExtendNone)
Else
If ThisDrawing.MSpace = True Then ThisDrawing.MSpace = False
Set ray = ThisDrawing.PaperSpace.AddRay(pt, ptx)
ins = ray.IntersectWith(e, acExtendNone)
End If
ray.Delete
If UBound(ins) = -1 Or (((UBound(ins) + 1) / 3) Mod 2) = 0 Then ok = False Else ok = True
InsideVP2 = ok
End Function

Did you ever try to obtain the entity that clips a PViewport? Getting the Viewport is easy, but now the corrsponding clipping entity...
The only way I found is obtaining the entity in the 340 dxf-code of the PViewport. And that only worked in LISP. Could it be that the
{ACADREACTORS} data of the clipping entity gives trouble, that I should replicate the "clipper" without the {REACTORS} and use that as my reference to check?
0 Likes
Message 5 of 7

Anonymous
Not applicable
Hi Gadger, I tried your suggestion with a ray, and it works in a singular way, meaning I can run the macro once. If I run it in a loop it just gives
nothing, in my case failing gives false. I'm checking a few hundred points in a go, all fail within a circle, but with a LWPolyline it does work.
I split the inside function in 2, one for polylines and another for circles, the last entirely calculates the intersections completely mathematicaly,
no acad, that does not fail... just check if the point is between the intersections with a horizontal line thru that point. Doing that for polylines is a hassle, and it works with vba, so why bother?
0 Likes
Message 6 of 7

Anonymous
Not applicable
hi lucaso, interesting to hear, i never needed to check if a point was inside a polyline or a circle yet, i think i just heard that somewhere. i was thinking that a ray could end up being tangent to a closed polyline, but the odds were... but then i guess it depends
0 Likes
Message 7 of 7

Anonymous
Not applicable
hi cadger, your suggestion was kinda right, it does work, but because of some bug in vba 2008 it doesn't work in a loop.
a lot of people are working on positioning certain objects, such as outlets, in drawings, putting the coordinates in a database,
to visualize it. I'm working on a shortcut, using the coordinates for bookmarks in a PDF, my favored publishing medium.
All you need is the Reader, self contained, and it works on a PDA. Try figuring out where a certain window goes in a 30-story building without all your plans blowing in the wind, and it's fast and printable.
Problem is that PViewports can be clipped and the views twisted, still need the correct coordinates, so I need to know if a certain point is inside a viewport. It's all rather complex, especially if things don't work out as you think it will (bugs).
But the combination of LISP with AC-commands and VBA does solve most problems.
0 Likes