doerner Posted December 15, 2012 Posted December 15, 2012 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 Quote
Dadgad Posted December 15, 2012 Posted December 15, 2012 (edited) 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! Edited December 15, 2012 by Dadgad Quote
GP_ Posted December 15, 2012 Posted December 15, 2012 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 ) Quote
doerner Posted December 15, 2012 Author Posted December 15, 2012 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 Quote
Lee Mac Posted December 15, 2012 Posted December 15, 2012 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! Quote
pBe Posted December 16, 2012 Posted December 16, 2012 ... I had fun writing this one.... I'm pretty sure you did Lee 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) ) Quote
Recommended Posts
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.