Jump to content

How to figure out what block to insert with the measure command


broncos15

Recommended Posts

So I have been working on a LISP routine to help automate parking layout, especially when there is curve. I make use of the measure command coupled with the offset command. The issue I run into is that it only works if the pline is one direction. If the pline is reversed it does not work properly because of the way that I have my block defined (I define the block in the LISP routine based on the dimensions that the user wants). I cannot think of a way to tell if I should use block 1 (oriented normally), or block 2 (which would be rotated 180 degrees to ensure that it gives a proper result). Can anyone think of an easy way to tell which block to use. Attached is an image that shows my problem.

Parking Layout Issue.jpg

Link to comment
Share on other sites

If you always have LWPOLYLINE as path curve, you can check its clockwise-p orientation and according to that decide what version of block to use for MEASURE...

 

 (defun ListClockwise-p (lst / z vlst)
   (vl-catch-all-apply 'minusp 
     (list
       (if 
         (not 
           (equal 0.0
             (setq z
               (apply '+
                 (mapcar 
                   (function
                     (lambda (u v)
                       (- (* (car  u) (cadr  v)) (* (car  v) (cadr  u)))
                     )
                   )
                   (setq vlst
                     (mapcar
                       (function
                         (lambda (a b) (mapcar '- b a))
                       )
                       (mapcar (function (lambda (x) (car lst))) lst) 
                       (cdr (reverse (cons (car lst) (reverse lst))))
                     )
                   )
                   (cdr (reverse (cons (car vlst) (reverse vlst))))
                 )
               )
             ) 1e-6
           )
         )
         z
         (progn
           (prompt "\n\nChecked vectors are colinear - unable to determine clockwise-p of list")
           nil
         )
       )
     )
   )
 )

 

More info :

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/polyline-direction-clockwise-or-counterclockwise/td-p/6050612

 

HTH, M.R.

Link to comment
Share on other sites

Marko, that is such a cool routine. So I am trying to figure out what value it exactly returns and what type of input it gives. My selection was made using entsel, and I tried to do

(ListClockwise-p (car ent))

but this isn't the right entity type.

Link to comment
Share on other sites

It uses point list (vertices list - or points along its length) in correct order obtained from LWPOLYLINE...

Link to comment
Share on other sites

Thanks Lee, I should have checked your website first. I had one more quick question in regards to how to shorten the beginning portion of pline by a given amount at the start of the pline. I know how to get the starting point using vlax-curve functions, and I have tried to adjust it then using the lengthen command through LISP by giving it the start point and the delta (in this case a negative delta), but I can't seem to get it work right.

Link to comment
Share on other sites

I had one more quick question in regards to how to shorten the beginning portion of pline by a given amount at the start of the pline. I know how to get the starting point using vlax-curve functions, and I have tried to adjust it then using the lengthen command through LISP by giving it the start point and the delta (in this case a negative delta), but I can't seem to get it work right.

 

I would check whether the starting segment is a linear segment or arc segment, calculate the new coordinates of the starting vertex based on the length or arc-length to be subtracted (also removing any intermediate vertices which lie on the section of the polyline to be removed), calculate the new bulge data (if working with an arc segment), and then entmod the modified DXF data.

 

Essentially the reverse of the method I use in my Double Extend program.

Link to comment
Share on other sites

Lee, thank you so much for the help! So I have continued to mess around with this code and it continues to get more complicated. I have it always working now when a user select the pline inner side of an arc, but it doesn't work properly when the user selects the outside of an arc. Attached is an image to show what I mean. What I think I need to do is have a test that would test if the user selected the inside or outside, and if so I have 2 different codes (I can't think of any way of how to do this when there are 2 different arcs in a pline which bow in different directions I think it would get way to complicated). Is it possible to do a test like this?

Parking Layout Issue2.jpg

Link to comment
Share on other sites

So I have been messing around with this some more and I think I solved it, but I can't get my function to work correctly. I am trying to see if the last object created using the measure command intersects with the original entity and if not, then reverse the pline and rerun. My code to check if they don't intersect is

(if (not (vla-IntersectWith lw (vlax-ename->vla-object prkstrp) acExtendNone))

Where lw is the original object that was converted to vla-object at an earlier point and prkstrp is the last object created by the measure command

(setq prkstrp (entlast))

This is inserted right after the measure command runs. The problem is that the if not statement isn't running, even when the objects don't intersect. Can anyone see what I am doing incorrectly?

Edited by broncos15
Edited code
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...