Lisp help please

Lisp help please

Charlie.ford7Z4SW
Explorer Explorer
529 Views
6 Replies
Message 1 of 7

Lisp help please

Charlie.ford7Z4SW
Explorer
Explorer

 

 

(defun c:APV (/ ss1 Lastent TargEnt TargLayer undo obj ss of en pt ent) 
 		(setq SS1 (ssadd))
 		(setq LastEnt (entlast))
		(while (setq TargEnt (car (entsel "\nSelect object on layer to select: "))) 
  		(setq TargLayer (assoc 8 (entget TargEnt)))
  		(sssetfirst nil (ssget "_X" (list TargLayer)))
   		(defun *error* (msg)
   		(or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
      		(princ (strcat "\n** Error: " msg " **")))
   		(princ)
  		)

	(if (and (ssget '((0 . "ARC,CIRCLE,ELLIPSE,*LINE")))
          (setq of (getdist "\nSpecify Offset Distance: ")))
   (progn
     (setq undo
       (not
         (vla-StartUndomark
           (setq doc
             (vla-get-ActiveDocument
               (vlax-get-acad-object)
             )
           )
         )
       )
     )  
     (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc))
       (mapcar
         (function
           (lambda ( o )
             (vl-catch-all-apply
               (function vla-offset) (list obj o)
             )
           )
         )
         (list of (- of))
       )
     )
     (vla-delete ss)
	(setq undo (vla-EndUndoMark doc))
   )
 )
)
(if (setq en (entnext LastEnt))  ;adds all offsets to SS1
      (while en
        (ssadd en SS1)
        (setq en (entnext en))))

 (while (setq pt (getpoint "\nPick internal point: "))
   (command "_.-boundary" "_a" "_i" "_n" "" "" "_non" pt "")
) 
  (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS1)))
    (entdel ent) 
)                
(princ)
)

 

 

Hello I need some help please. I have put together this code here. the working principles of this is to do the following 

Select all objects layer

Offset distance = 

Select all objects  layer

Offset distance = 

Offsets are done in and out of every layer that is selected at the required offset distance.

Boundary command is done to work out the internal boundary of area selected

Continue onto the next boundary to select

when exiting the command the offsets that were produced are deleted the only thing to remain is the boundary lines

 

But there is a bit of a problem with this command as shown below 

Charlieford7Z4SW_0-1669378094156.png

Charlieford7Z4SW_1-1669378157667.png

Charlieford7Z4SW_2-1669378187172.png

as you can see the boundary that was created in pink did not consider the white polyline in this boundary. So I thought then the polylines that are offset should be a closed shape but I dont know how to do that in lisp so if anyone knows how to do this that would be great.

I found this 

https://cadtips.cadalyst.com/linear-objects/draw-a-cap-or-pipe-end?q=linear-objects/draw-a-cap-or-pi...

which I used and it is really good but it needs to close these objects automatically without me selecting anything.

I appreciate any help that can be given I appreciate it might not be possible.  

Cheers

 

0 Likes
Accepted solutions (1)
530 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant

Post a sample drawing - one with the initial state, the second with the desired result.

Also could explain why you're bounding those two things together? Offset and making boundaries to erase internal objects? It seems to me like two different processes...

0 Likes
Message 3 of 7

Charlie.ford7Z4SW
Explorer
Explorer

Apologies BeekeeCZ new to this. I am bounding these two offset objects in order so that the boundary command goes around it. For example I have a wire in that drawing I want to keep 3m away so i need the object to close so I dont get too close to it or cut through it with the boundary. 

 

I think I have a solution to the problem here where the layer that is selected it puts a small circle at the end of all the polyline i.e 0.01m. Then when the layer is offset it is 'joined' by the circle and the boundary can be done around it.

Charlieford7Z4SW_0-1669394872678.pngCharlieford7Z4SW_1-1669394900849.pngCharlieford7Z4SW_2-1669394951252.png

So I dont know how this can be done but I guess it would work something like so 

Select the layer 

It puts a small 0.01m circle block 

offset is done 

boundary is selected 

offsets and circles are deleted 

 

BeekeeCZ does that make a bit more sense?

 

0 Likes
Message 4 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

Try this if it helps.

 

(vl-load-com)

(defun c:APV ( / *error* hid osm n d y s o p l)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if hid (setvar 'hpislanddetection hid))
    (if osm (setvar 'osmode osm))
    (if l (foreach e l (entdel e)))
    (princ))
  
  ; ========================================================================================================
 
  (setq hid (getvar 'hpislanddetection)) (setvar 'hpislanddetection 2)
  (setq osm (getvar 'osmode)) (setvar 'osmode 0)
  (setq n (entlast))
  
  (while (and (setq e (car (entsel "\nSelect object on Layer to select: ")))
	      (setq d (getdist "\nSpecify Offset Distance: "))
	      (setq y (assoc 8 (entget e)))
	      (setq s (ssget "_X" (list '(0 . "ARC,CIRCLE,ELLIPSE,LINE,LWPOLYLINE") y (cons 410 (getvar 'ctab)))))
	      )
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i)))
	    o (vlax-ename->vla-object e))
      (vl-catch-all-apply 'vla-offset (list o d))
      (vl-catch-all-apply 'vla-offset (list o (- d)))
      (and (or (wcmatch (cdr (assoc 0 (entget e))) "ARC,LINE")
	       (and (= (cdr (assoc 0 (entget e))) "LWPOLYLINE")
		    (zerop (getpropertyvalue e "Closed"))))
	   (entmake (list '(0 . "CIRCLE") y (cons 10 (vlax-curve-getstartpoint e)) (cons 40 (+ 0.01 d))))
	   (entmake (list '(0 . "CIRCLE") y (cons 10 (vlax-curve-getendpoint e)) (cons 40 (+ 0.01 d)))))))
  
  
  (while (setq n (entnext n)) (setq l (cons n l)))
  (while (setq p (getpoint "\nPick internal point: ")) (bpoly p))
  
  (*error* "end"))

 

0 Likes
Message 5 of 7

Moshe-A
Mentor
Mentor

@Charlie.ford7Z4SW  hi,

 

To tell you the truth, i do do not understand what you are doing and and why a lisp is needed anyhow i accepted the challenge 😀  attached apv2 command and here is the prompts:

 

Command: APV2

Select rectangle...
Select objects:  < pick rectangle >

Select penetrating line...
Select objects:  < pick the crossing line >

Inward offset <3.0000>:   < specify offset >

 

rules:

the rectangle must be right angle of 4 segments and can be laid at any angle. 

the line (call it penetrating line) must cross the short edge and need to be perpend to it but not need to cross it at middle point. the inside penetrating line point would serve as a guide to place the center of the arc parallel to short edge. the length of short edge must be at least 6 time the specified offset. an error message is echo when rules are not fulfill.

 

enjoy

Moshe

 

0 Likes
Message 6 of 7

Charlie.ford7Z4SW
Explorer
Explorer

Hi @ВeekeeCZ That is fantastic tested and all and seems to be working brilliantly. Thank you!! save days of my life doing it manually.

@Moshe-A So for context of the code that you also wrote, it is to automatically generate a fence line for fields. I work in the solar industry and design solar projects. This handy lisps keeps the fence offset from things it is not meant to be close too (hedges, drains, telecoms ect). Thank you for your help and hope it feels a bit more satisfying now you know what the code does.

 

Can't thank you guys enough very pleased.

0 Likes
Message 7 of 7

Moshe-A
Mentor
Mentor

@Charlie.ford7Z4SW ,

 


@Charlie.ford7Z4SW wrote:

Hi @ВeekeeCZ That is fantastic tested and all and seems to be working brilliantly. Thank you!! save days of my life doing it manually.

@Moshe-A So for context of the code that you also wrote, it is to automatically generate a fence line for fields. I work in the solar industry and design solar projects. This handy lisps keeps the fence offset from things it is not meant to be close too (hedges, drains, telecoms ect). Thank you for your help and hope it feels a bit more satisfying now you know what the code does.

 

Can't thank you guys enough very pleased.


Please solved this puzzle for me 😁

 

"it is to automatically generate a fence line for fields"

what do you mean by that?

 

how the lisp you brought in message 1 of 6 settles with the pictures in your message  3 of 6?

and where is the small 0.01m circle block?

 

Moshe

 

0 Likes