Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

create layer + add number

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
marymAGTL5
385 Views, 6 Replies

create layer + add number

Is something like the following possible? It's been a long time since I've had to research/create a command/lisp. Any help is appreciated. 

 

I would like the command to create a layer (A-Rev-Cloud#) and then ask for the number of the revision. It will then put the revision number at the end of the layer name. 

If the layer is not in the drawing, it creates it. 

 

We don't always have succession in revision numbers for each sheet. So, having the command ask the revision number, then create the layer will save a lot of time and streamline our production. 

 

6 REPLIES 6
Message 2 of 7
Kent1Cooper
in reply to: marymAGTL5

It would even be possible to have it check whether there are any such Layers in the drawing already.  If not, it could offer you "A-Rev-Cloud1" as a default that you could just accept, or if there are any already, it could offer you the name with the next as-yet-unused number at the end, as a default.  In either case it could let you specify a suffix number that is not the next one, if you have a reason to.  Would something like that suit your purpose?

EDIT:  Just because -- for example:

(defun C:RCL# ; = make or set Revision Cloud Layer with # suffix
  (/ suf layname)
  (setq suf 0)
  (while (tblsearch "layer" (strcat "A-Rev-Cloud" (itoa (setq suf (1+ suf))))))
  (initget 6); no zero, no negative
  (setq layname
    (strcat
      "A-Rev-Cloud"
      (itoa
        (cond
          ( (getint
              (strcat
                "\nRevision Cloud Layer number <"
                (itoa suf)
                ">: "
              ); strcat
            ); getint
          ); User-input condition
          (suf); on Enter to accept default
        ); cond
      ); itoa
    ); strcat
  ); setq
  (command "_.layer" "_make" layname "_color" 2 "" ""); <--EDIT color
  (prin1)
)

Edit the desired Layer color, and add other options if you like.  [It assumes you would want that to be the same for all such Layers.]

It offers as default the next available number, but you can enter any number you want if you don't want the default that it's offering.  So you can set an earlier revision-number Layer current if you need to, such as to just get into the current one rather than make another [type in one less than it's offering].  Or you can even jump beyond the next available number if you have reason to omit intervening numbers.  If the Layer with the number doesn't exist, it will make it.  If it does already, it will simply become current.

Kent Cooper, AIA
Message 3 of 7
marymAGTL5
in reply to: Kent1Cooper

@Kent1Cooper This is exactly what I need and it works perfectly. Thank you so much. 

Message 4 of 7
ancrayzy
in reply to: marymAGTL5

Thank you @Kent1Cooper , for the code.

I have adjusted it so that you can now choose colors more flexibly in the "Autocad color Index" color palette, instead of the default color always being number 2. However, at the end of the command, there is still the line 'Enter an option,' which is quite annoying because you have to press Enter to finish the command. If you don't mind that, you can use it.

;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/create-layer-add-number/td-p/12854019
;Thank Kent1Cooper
(defun C:RCL# ; = make or set Revision Cloud Layer with # suffix
  (/ suf layname col)
  (setq suf 0)
  (while (tblsearch "layer" (strcat "A-Rev-Cloud" (itoa (setq suf (1+ suf))))))
  (initget 6) ; allow only positive non-zero integers
  (setq layname
    (strcat
      "A-Rev-Cloud"
      (itoa
        (cond
          ((getint
              (strcat
                "\nRevision Cloud Layer number <"
                (itoa suf)
                ">: "
              ))
           )
          (suf)
        )
      )
    )
  )
  (setq col (acad_colordlg 1 T)) ; <-- Display color selection dialog, default to color 1
  (if col
    (progn
      (command "_.layer" "_make" layname "_color" col "")
      (princ (strcat "\nSelected color: " (itoa col)))
    )
    (princ "\nNo color selected.")
  )
  (prin1)
)
Message 5 of 7
Kent1Cooper
in reply to: ancrayzy


@ancrayzy wrote:

... at the end of the command, there is still the line 'Enter an option,' which is quite annoying because you have to press Enter to finish the command. ....


Just include it [another ""] at the end of your code line 28, as is done in my line 24.

Kent Cooper, AIA
Message 6 of 7
marymAGTL5
in reply to: Kent1Cooper

@Kent1Cooper The first one is perfect but I'll keep this one as well in case the other people in my dept have suggestions. We don't always have successive rev #'s. I'm currently working on sheets that have revisions 1,2,6 & 18. So, inputting the # is perfect. 

I was able to change the color to our in-house standard. Works beautifully! Thank you for creating this for me. I would have lost my mind, and a lot of time, trying to do this. 

Message 7 of 7
ancrayzy
in reply to: Kent1Cooper

Perfect @Kent1Cooper , Thank you so much.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta