vla-offset with polylines (LWPOLYLINE)

vla-offset with polylines (LWPOLYLINE)

Jonathan_Bell82GXG
Enthusiast Enthusiast
513 Views
5 Replies
Message 1 of 6

vla-offset with polylines (LWPOLYLINE)

Jonathan_Bell82GXG
Enthusiast
Enthusiast

I'm trying to figure out how (vla-offset) works with polylines. My findings so far:

  • blue indicates the offset
  • draw order is indicated by the numbers
  • each group of polyline segments has been joined into 1 polyline
  • offsetting is done using (vla-offset (vlax-ename->vla-object (car (entsel))) 4) at the command line

vla-offset.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

In the first column, offsets seem to follow these rules:

  • Individual PLINE drawn left to right = offset below
  • PLINE right to left = above
  • PLINE top to bottom = left
  • PLINE bottom to top = right

However, as shown in the second column in the picture, when the original pline is exploded and a particular segment is deleted and replaced with a PLINE segment with a reversed drawing order, the offset gets flipped. Seems to be the case with closed plines as well. 

 

Is all this correct? Is there a more comprehensive vla-offset reference somewhere?

 

 

To give more context, I'm trying to offset a given polyline (at least 2 segments and up to 4) so that the offset is always on the outside of the polyline, no matter what changes are made to the entity to be offset before the offset function is used. If there's a better method for doing this than using vla-offset let me know! (Also, I plan on making a separate algorithm for joining connected lines or groups of lines and polylines into just polylines and then going from there).

 

Thanks!

0 Likes
Accepted solutions (1)
514 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

In the case of Polylines, a positive offset value goes to the right from the point of view of the drawn direction of the Polyline; negative to the left.

 

A routine that figures out which of those to use depending on whether you want to go inboard or outboard, and that works with various object types that can have an "inside" and "outside," is OffsetInOrOut.lsp, >here<.  It defines two commands:  OffIn and OffOut.  See variant forms of it later in that topic.

 

 

Kent Cooper, AIA
Message 3 of 6

hak_vz
Advisor
Advisor
(defun c:offlw (/ pick_poly e eo offvalue)
	(defun pick_poly (msg)
		(setq e (car(entsel (strcat "\n" msg " >"))))
		(if (and (not e) (= (getvar 'Errno) 7)) (pick_poly msg) e)
	)
	(setq e (pick_poly "\nSelect entitiy to offset >"))
	(setq eo (vlax-ename->vla-object e))
	(cond 
		((vlax-method-applicable-p eo 'offset)
		(setq offvalue (getreal "\nEnter offset distance >"))
		(vla-offset eo offvalue)
		)
	)
	(princ)
)

The distance to offset the object can be a positive or negative number, but it cannot equal zero. If the offset is negative, this is interpreted as being an offset to make a "smaller" curve (that is, for an arc it would offset to a radius that is "Distance less" than the starting curve's radius). If "smaller" has no meaning, then it would offset in the direction of smaller X, Y, and Z WCS coordinates.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 4 of 6

Kent1Cooper
Consultant
Consultant

@hak_vz wrote:

.... If the offset is negative, this is interpreted as being an offset to make a "smaller" curve ....


That happens to be true for an Arc or a Circle or an Ellipse, because for them, a negative value offsets to the left from the point of view of the "drawn direction," which is always counterclockwise for those, so a negative value always goes inward.  But it's not true for a Polyline.  These two white Polylines are identical except that they were drawn in opposite directions [the arrows]:

Kent1Cooper_0-1691517475329.png

and the green is the result of (vla-offset) with a positive value in both cases.  Positive goes to the right, negative to the left -- it has nothing to do with larger or smaller.  The same is true for a Spline, but for who-knows-what reason, for a Line, positive goes left, negative goes right.

Kent Cooper, AIA
Message 5 of 6

Jonathan_Bell82GXG
Enthusiast
Enthusiast
If I'm understanding your code right, seems like the core of the algorithm is comparing the area of the offset entity and the original entity and deleting & redoing the offset (with a negative offset dist) if necessary. Just out of curiosity, are there any other methods that might work for creating just outward offsets? Your method should work perfectly for my application, just wondering if there are any other options you've come across or can think of.
0 Likes
Message 6 of 6

Kent1Cooper
Consultant
Consultant

@Jonathan_Bell82GXG wrote:
.... the core of the algorithm is comparing the area of the offset entity and the original entity and deleting & redoing the offset (with a negative offset dist) if necessary. ... are there any other methods ... for creating just outward offsets? ...

There's an approach that @john.uhden often brings up, which is to look at the object type, and if it's certain kinds, you can know which sign to put on the (vla-offset) value to go in the right direction, but if it's a Polyline, you need to determine whether its drawn direction is CW or CCW, from which you can decide the sign.  See his Message 11 at the topic I linked to for the routine, and subsequent discussion.

Kent Cooper, AIA