Jump to content

Recommended Posts

Posted

I have a routine that I've been using but I would like to modify it just a bit. The function is for creating Deed Sketches that allows the user to create a new layer and select a color. It works great but if you happen to exit the command, and need to start again, it still asks for a new layer. I would like to change the code to have the option to first, USE THE CURRENT LAYER. If not then I would have the option I already have, which is to create the new layer but then I need to, if that layer already exists, set it to current. Here is that portion of the code. I've tried tons of different ways but I know just enough about lisp routines to get myself into trouble.

 

;main program

(DEFUN C:deed ()

 

(while

(or

(not (snvalid (setq name (getstring t "\nSpecify Layer Name: "))))

(tblsearch "LAYER" name)

)

(princ "\nLayer Name Invalid or Already Exists.")

)

(if (setq color (acad_colordlg 7 nil))

(entmake

(list

(cons 0 "LAYER")

(cons 100 "AcDbSymbolTableRecord")

(cons 100 "AcDbLayerTableRecord")

(cons 2 name)

(cons 70 0)

(cons 62 color)

)

)

)

(command "layer" "s" NAME "")

Posted

Hi,

 

Modify While loop as below.

This will checks the layer name for vlididty. It it is a valid layer then checks weather it already exists or Not.

If the layer exists sets the layer as current layer.

I hopes this works for you.

 

 

(DEFUN C:deed ()

(setq newlayer T)
(while (not (setq name (getstring t "\nSpecify Layer Name: ")))
(if (tblsearch "LAYER" name)
 (progn (command "Layer" "S" name "") (setq newlayer nil))
 (princ "\nLayer Name Invalid.")
 )
 )

(if newlayer
 (progn
   (if (setq color (acad_colordlg 7 nil))
     (entmake
(list
  (cons 0 "LAYER")
  (cons 100 "AcDbSymbolTableRecord")
  (cons 100 "AcDbLayerTableRecord")
  (cons 2 name)
  (cons 70 0)
  (cons 62 color)
  )
)
     )
   (command "layer" "s" NAME "")
   )
 )
)

Posted (edited)

Welcome to the forum. :)

 

What you are trying to do, while not exactly the same,

brings to mind one of my very favorite lisps, which runs nonstop on my machines.

That is Lee Mac's LAYER DIRECTOR.

Thanks Lee! :beer:

 

Everybody should use this lisp, it is simply brilliant, and very easily modified to suit personal needs,

even by those who are lisp-challenged, like myself.

This is but one of a great many wonderful lisps generously made available

on Lee's site. Do yourself a favor, check them out. :thumbsup:

Edited by Dadgad
Posted (edited)

This works Giskumar but if the layer exists, it still promps me for a color.

Edited by clint0577

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