Jump to content

Recommended Posts

Posted

Hi all,

 

I’m new to creating LISP routines and am hoping for some tips on the below.

 

I’m looking to create a lisp routine for the following

 

·         Create a new layer

·         User selects a closed poly line 

·         User enters a width for the polyline

·         Polyline’s width is set accordingly.

·         Polyline’s layer is changed to newly created layer

·         The polyline is offset based on half the width value given

·         Hatch created from the offset polyline

·         Delete original polyline

 

I’ve done some research and I’ve managed to do all the above with the exception of hatching from the offset polyline. I can hatch from the original polyline; however, I’m not sure how I can get the routine to reference the new offset polyline to create a hatch from there… I may well be missing something quite basic.

 

Here is what I have so far. I’m aware it’s good practice to add error handling etc.

 

(defun C:ofh (/ ulw userlayer obj)
(setq userlayer (getvar "CLAYER"))
(command "-layer" "M" "FLAT TYPE 1" "C" "RED" "" "") 
(setq ulw (getint "\nEnter Boarder Line width: "))
(setq obj (entsel "\nPick line")) 
(command "-hatch" "P" "NET" "50" "45" "S" obj "" "")
(command "_pedit" obj "W" ulw "") 
(command "_CHPROP" obj "" "LA" "FLAT TYPE 1" "")
(command "_offset" (/ ulw 2) obj pause "")
(command "Erase" obj "")
(setvar "CLAYER" userLayer)

 

Any pointers, tips, refinements  etc would be very much appreciated.

 

Thanks,

Phil

 

 

Posted (edited)

Welcome to CADTutor forums poccles.

That is a very good first post, with which I can't personally help you.

However there are many who will be able to, and you have helped them to help you

by explaining where you are at and where you want to go, without first playing a protracted energy and time wasting game of 20 Questions.

 

As a newbie to, and student of lisp, do yourself a huge favor and visit LeeMac's excellent website.

You will be well rewarded for time spent there.

Lee is great, and very generous with the global Cad and lisp community.

To the best of my knowledge he is not a  Norwegian Female Power Trio guitarist, as was erroneously suggested by

my having supplied an incorrect link a few days ago.     :huh:  ;)

 

BUT he is a total lisp-meister and held in very high esteem by forum members and users of his wonderful tools!

 

Thanks Lee!   :beer:

Edited by Dadgad
typo
Posted

I don't know if this is exactly what you wanted, but give it a try.

(defun C:ofh (/ ulw userlayer obj)
   (setvar "cmdecho" 0)
   (vl-cmdf "_.undo" "_begin")
   
   (setq userlayer (getvar "CLAYER"))
   (command "_.layer" "M" "FLAT TYPE 1" "C" "RED" "" "") 
   (setq ulw (getint "\nEnter Boarder Line width: "))
   (setq obj (entsel "\nPick line")) 
   (command "_.pedit" obj "W" ulw "") 
   (command "_.CHPROP" obj "" "LA" "FLAT TYPE 1" "")
   (command "_.offset" (/ ulw 2) obj "0,0" "")
   (command "_.hatch" "P" "NET" "1" "45" "S" "_l" "" "")
   (command "_.Erase" obj "")
   (setvar "CLAYER" userLayer)

   (vl-cmdf "_.undo" "_end")
   (princ)
)

 

Posted

Something based on your code. :)

;Create from Trudy
;Date: 12.03.2021
(defun c:try1 ( / laynam oldlay wild sel)
(setq laynam (getstring "\nEnter layer name: "))
(setq wild (getreal "\nEnter wildh: "))
(command "-layer" "M" laynam "C" "RED" "" "")
(setq sel (entsel "\nSelect closed polyline"))
(command "offset" (/ wild 2) sel pause "")
(entmod (subst (cons 43 wild) (assoc 43 (entget (entlast))) (entget (entlast))))
(entmod (subst (cons 8 laynam) (assoc 8 (entget (entlast))) (entget (entlast))))
(command "-hatch" "P" "NET" "50" "45" "S" (entlast) "" "")
(entdel (car sel))
(princ)
)

 

Posted

That's a great help, thanks very much all 👍

 

Slightly different approaches, I'll have a look at both and see what's going on.

 

And thanks greeting and the LeeMac link, Dadgad - I'm sure it'll be a useful resource.

Posted

Good to see you having a go will get more help at times.

 

I would keep the pause in the offset as you want choice left or right, wont go into it now but can automate that also based on end of line you pick sets left and right automatically.

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