Jump to content
doerner

Hatch of Closed Polylines Offset From User Designated Points

Recommended Posts

doerner

I am pretty new to lisps, but I think that I have made this a little more complex than it needs to be.

 

I am trying to create a offset box around a set polyline and then hatch the box. I have succeeded in making it work for four user designated points, but I am looking for more.

 

I would like to be able to run the lisp, draw a polyline with infinite bends and angles, and then have it hatch the resulting offset box.

 

If anyone has any optimization ideas I would love to hear them

trench.lsp

photo (4).jpg

Capture.JPG

Share this post


Link to post
Share on other sites
Dadgad

Welcome to CADTutor. :)

 

You could quite easily define a MULTILINE style, and it would draw your lines,

and you can set the line justification however you want it, I am guessing to center.

It would create all three lines simultaneously, on the fly, either with end closures

or not.

 

As a student of lisp, you may want to visit Lee Mac's site, you would certainly be able to learn a great deal by

studying his wonderful lisps.

 

He has one which may provide some clues to your current lisp in development,

http://www.lee-mac.com/dynamicoffset.html

 

Thanks Lee! :beer:

Edited by Dadgad

Share this post


Link to post
Share on other sites
GP_

Try, on lwpolylines with width > 0.00

(by confutatis)

 

(defun C:PL2CAN ()
(setvar "PEDITACCEPT" 1)
(setvar "CMDECHO" 1)
(setq gru(ssget '((0 . "LWPOLYLINE")))
      index -1
      modelspace(vla-get-Modelspace (vla-get-activedocument(vlax-get-acad-object)))
)
(setvar "HPNAME" "ANSI31")
(setvar "HPSCALE" 1)
(repeat (sslength gru)
 (setq spessore(vla-get-ConstantWidth (vlax-ename->vla-object (ssname gru (setq index(1+ index))))))
 (vla-put-ConstantWidth (vlax-ename->vla-object (ssname gru index)) 0.0)
 (setq ent1(car(vlax-safearray->list (vlax-variant-value (vla-offset (vlax-ename->vla-object (ssname gru index)) (/ spessore 2))))))
 (setq ent2(car(vlax-safearray->list (vlax-variant-value (vla-offset (vlax-ename->vla-object (ssname gru index)) (-(/ spessore 2)))))))
 (setq coord1 (variant2lista (vla-get-coordinates ent1) 2))
 (setq coord2 (variant2lista (vla-get-coordinates ent2) 2))
 (cond
  ((eq (vla-get-Closed ent1) :vlax-true)
   (vl-cmdf "_HATCH" "" "" "" (vlax-vla-object->ename ent1)(vlax-vla-object->ename ent2) "")
  )
  ((eq (vla-get-Closed ent1) :vlax-false) 
   (vla-addLine modelspace (vlax-3d-point (car coord1))(vlax-3d-point (car coord2)))
   (vl-cmdf "_PEDIT" (entlast) "_J" (vlax-vla-object->ename ent1)(vlax-vla-object->ename ent2) "" "_CL" "")
   (vl-cmdf "_HATCH" "" "" "" (entlast) "")
  )
 ) 
)
)

;;; ***************************FUNZIONE VARIANT2LISTA*******************************
;;; Trasforma un variant in una lista a gruppi con numero elementi per gruppo
(defun variant2lista (listavariant numero / listaparz listafin)
(setq listaparz '()
      listafin   '()
)
(foreach elemento (vlax-safearray->list (vlax-variant-value listavariant))
 (setq listaparz (append listaparz (list elemento)))
 (if (= (length listaparz) numero)
  (setq listafin  (append listafin (list listaparz))
    listaparz '()
  )
 )
)
listafin
)

Share this post


Link to post
Share on other sites
pBe

Looks fun to code... :popcorn:

Share this post


Link to post
Share on other sites
doerner
My version:

 

[ATTACH]39264[/ATTACH]

 

Lee, that looks like exactly what I was looking for. And thanks to the rest of you. I haven't got my comp with me this weekend, but I will test them all out on Monday.

 

Thanks again

Share this post


Link to post
Share on other sites
Lee Mac
Lee, that looks like exactly what I was looking for. And thanks to the rest of you. I haven't got my comp with me this weekend, but I will test them all out on Monday.

 

Thanks again

 

You're very welcome, I had fun writing this one.

Let me know how you get on!

Share this post


Link to post
Share on other sites
pBe
... I had fun writing this one....

 

I'm pretty sure you did Lee :thumbsup:

 

Here's a no-nonsense vanilla code to pass the time :)

 

(defun c:hatsoff ( / ss e ent fp sp el el2 elj)
(setvar 'cmdecho 0)      
     	
(if     (and  (setq dist (getdist "\nEnter Offset Distance: "))  
     		(setq ss (ssget '((0 . "LWPOLYLINE")))))
(repeat (sslength ss)
   (if (and
(setq e (ssname ss 0))
(setq ent (entget e))
(setq  fp (assoc 10 ent) ent (member fp ent)
              sp (cdr (assoc 10 (cdr ent))) fp (cdr fp))
(setq fp (polar fp (setq ang (+ (angle fp sp) (/ pi 2.0)))  dist))
(not (command "_offset"  dist e "_non" fp "E"))
(setq el (entlast))
(not (eq el e))
(not (command "_offset"  dist e "_non" (setq sp (polar fp (+ ang pi) (+ dist dist))) "E"))
(setq el2 (entlast))
(not (eq el el2)))
        (progn
               (if (= 1 (cdr (assoc 70 (entget el))))
                (command "_hatch" "ANSI31" "" "" "_s" el el2 "")
                (progn  
        	(command "_pline" "_non" fp "_non" sp "")
        	(command "_pedit" "_multiple" el el2 (entlast) "" "_join" "" "")
		(setq elj (entget (entlast)))
		(entmod (subst '(70 . 1) (assoc 70  elj) elj))
                       (setvar 'Hpname "ANSI31")
		(command "_hatch" "" "" ""  (entlast) "")
                )
                  )
        )
       )
(ssdel e ss)
     )
)
             (princ)
            )

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...