See the top rated post in this thread. Click here

Page 1 of 3 123 LastLast
Results 1 to 10 of 29

Thread: Set Linetype, Layer and start the Line command

  1. #1
    Woo! Hoo! my 1st post
    Join Date
    2014-05
    Posts
    1
    Login to Give a bone
    0

    Default Set Linetype, Layer and start the Line command

    I know this maybe a small project but it would help tremendously. I work in an engineering office where AutoCad is used on Plumbing, Mechanical and Electrical drawings. Each discipline has several line types
    Colors and layers. To manually set each one as needed is way to time consuming.

    I need a .lsp routine to set:
    -Color
    -Line type
    -Layer
    -Weight
    -Line type scale
    And
    -Start the line command

    If I had a (one) .lsp to do that, then I could copy and set up the rest of the lines.
    Please help if you can.
    Thank You
    Jerry
    bbryson_2000@yahoo.com

  2. #2
    I could stop if I wanted to
    Join Date
    2015-05
    Location
    West Des Moines
    Posts
    306
    Login to Give a bone
    0

    Default Re: Set Linetype, Layer and start the Line command

    I'll be really interested to see if anyone else has different versions of this type of lisp since this is the vast majority of the type of lisp I do.

    So here's three routines.

    Code:
    (defun trapUP (errmsg)
    	(setvar "clayer" oldlayer)
    	(setvar "plinegen" oldgen) 
    	(setvar "plinewid" oldwid)
    	(command "-linetype" "set" "Bylayer" "")
    	(setq *error* temperr)
    	(prompt "\nResetting System Variables ")
       (princ)
    )
    This is a trap that is referenced in each line command I write. UP stands for Utility Proposed. Can rename it to whatever you want, or just leave it if you're afraid to play with it. Essentially the trap is used so that if the user escapes during the command variables are reset. If the users hits return when they are done drawing the variables reset as part of the line's routine, thus the trap is the other end of making sure they reset properly.

    Code:
    (DEFUN C:SAS()
    	(setq cancel *error*)
    	(setq *error* trapUP)		
    	(setq oldlayer (getvar "clayer"))
    	(setq oldgen (getvar "plinegen"))
    	(setq oldwid (getvar "plinewid"))
    	(setvar "plinegen" 1)
    	(setvar "plinewid" 0.0)
    	(COMMAND "-LAYER" "MAKE" "UP-SS" "COLOR" "72" "" "Ltype" "U-SS" "" "lweight" ".6" "" "")
    		(COMMAND "PLINE" )
    		(while (> (getvar "CMDACTIVE") 0) (command pause))
    	(setvar "clayer" oldlayer)
    	(setvar "plinegen" oldgen)
    	(setvar "plinewid" oldwid)
    	(command "-linetype" "set" "Bylayer" "")
    	(setq *error* temperr)
       (princ)
    )
    Basically what you're looking for here. This is an undefined line command that doesn't describe pipe size.

    Code:
    (DEFUN C:4SS()
    	(setq cancel *error*)
    	(setq *error* trapUP)			
    	(setq oldlayer (getvar "clayer"))
    	(setq oldgen (getvar "plinegen"))
    	(setq oldwid (getvar "plinewid"))
    	(setvar "plinegen" 1)
    	(setvar "plinewid" 0.33)
    	(COMMAND "-LAYER" "MAKE" "UP-SS" "COLOR" "72" "" "Ltype" "U-SS" "" "lweight" ".6" "" "")
    		(COMMAND "-linetype" "SET" "U-SS-4" "")
    		(COMMAND "PLINE" )
    		(while (> (getvar "CMDACTIVE") 0) (command pause))
    	(setvar "clayer" oldlayer)
    	(setvar "plinegen" oldgen)
    	(setvar "plinewid" oldwid)
    	(command "-linetype" "set" "Bylayer" "")
    	(setq *error* temperr)
       (princ)
    )
    This is only slightly different in that before it runs the line command it sets it to the linetype you want. The end result is that your overall utility layer has a linetype that may not be used at all if you're almost always describing pipe sizes (like we do), but all the same utilities with different sizes are on the same layer. This makes it easy to isolate the layer to see all the lines you want.

    If you care about lineweight I think the plinewid variable messes with it, and you can delete that line of the code. Personally (and maybe someone wants to correct me) I'm not quite sure why people want to set weights to layers instead of just adjusting the width. I think the weights being set in my lines are useless because I also set the width to what I want, and I believe the plinewid variable has to be 0 for the weight to be factored in.

    On this topic here's a bonus: http://www.lee-mac.com/totallengthandarea.html

    This routine will allow you to measure all the selected lines or area instantly. It goes really well with isolating a utility and then grabbing all the lines.

  3. #3
    I could stop if I wanted to
    Join Date
    2012-11
    Location
    Brisbane, Australia
    Posts
    239
    Login to Give a bone
    1

    Default Re: Set Linetype, Layer and start the Line command

    I have made something similar for cleaning architectural backgrounds.
    You may be able to use a similar idea for doing the services.
    OMCleanDWG cleans up the original file and OMCleanLayers changes all the layer colours based upon some wildcards.
    I keep adding to the wildcard list to increase accuracy.

    Hope it helps.
    Attached Files Attached Files

  4. #4
    Login to Give a bone
    0

    Default Re: Set Linetype, Layer and start the Line command

    I'm thinking you might have clicked on the wrong request tag.
    I appreciate you trying. Cleaning up my file is not what I ask for.
    Here it is again.....

    I need a .lsp routine to set:
    Color
    Line type
    Layer
    Weight
    Line type scale
    And
    Start the line command
    If I had a (one) .lsp to do that, then I could copy and set up the rest of the lines.

  5. #5
    Login to Give a bone
    0

    Default Re: Set Linetype, Layer and start the Line command

    Thanks for trying.
    I didn't need the pline items so I deleted the lines.
    I changed the color number but didn't see how the change the layer name.
    This is all above my head so I gave up. I gave a list of items I needed but didn't see them in the .lsp file you sent.
    Thanks anyway

  6. #6
    I could stop if I wanted to
    Join Date
    2015-05
    Location
    West Des Moines
    Posts
    306
    Login to Give a bone
    0

    Default Re: Set Linetype, Layer and start the Line command

    I'll make this easier for you and you can try to expand on it later through traps if you want

    Code:
    (DEFUN C:SAS()
    	(COMMAND "-LAYER" "MAKE" "UP-SS" "COLOR" "72" "" "Ltype" "U-SS" "" "lweight" ".6" "" "")
            (COMMAND "LTSCALE" 1)
    	(COMMAND "PLINE" )
    )
    So to break this down...

    SAS is the command. Replace it with whatever you want, like EL for electric or whatever. Just make sure it doesn't overwrite existing commands like how pl is the default to start a polyline.

    Otherwise it is making a layer on the UP-SS layer on the color 72 with the linetype U-SS and a weight of .6. My suggestion is to pop open CAD and run the "-layer" command since that line of code is simply removing manual work and you'll get a better idea of how it works.

    All the extra code I gave you before was something you could consider optional, but when doing this type of work for multiple users it's considered correct to not permanently change their variables.

    edit: I dunno why you want to set your LT scale in the routine, but I added it in so you can. Just change the value to whatever you want.

  7. #7
    I could stop if I wanted to
    Join Date
    2015-10
    Location
    Colorado Springs, CO
    Posts
    369
    Login to Give a bone
    0

    Default Re: Set Linetype, Layer and start the Line command

    Why not set all the layers as a separate lisp and then use tool palettes to setup line buttons that do what you want?

    You could also do this with toolbars.

    Here is an example that setups up layers, it's just a snippet because the whole thing is 300+ layers. The way that this one works, it will also over-write any layers that already exist and update them to the standard you specify in the lisp.

    Code:
    (DEFUN C:companylayer ()
      
      (setq oldlayer (getvar "CLAYER"));get current layer
      (setq oldcmdecho (getvar "cmdecho"))
      (setvar "cmdecho" 0)
    
    ;;set linetype scale
      (COMMAND "LTSCALE" "your value")  
    
    ;;;load company linetypes
    (setvar "Expert" 3)
    (command "._linetype" "_load" "*" "[path for your custom linetypes].lin" "")
    (setvar "Expert" 0)
    
    ;;;ONE LINE LAYERS
    (COMMAND "LAYER" "MAKE" "E-1LIN" "C" "134" "" "")
    (COMMAND "LAYER" "MAKE" "E-1LIN-DEMO" "C" "40" "" "LT" "DASHED" "" "")
    (COMMAND "LAYER" "MAKE" "E-1LIN-EXST" "C" "84" "" "")
    (COMMAND "LAYER" "MAKE" "E-1LIN-IDEN" "C" "14" "" "")
    (COMMAND "LAYER" "MAKE" "E-1LIN-DEMO-IDEN" "C" "14" "" "")
    (COMMAND "LAYER" "MAKE" "E-1LIN-EXST-IDEN" "C" "14" "" "")
    (COMMAND "LAYER" "MAKE" "E-1LIN-IDEN-NPLT" "C" "5" "" "P" "N" "" "")  
    ;;;GENERAL LAYERS
    (COMMAND "LAYER" "MAKE" "E-ALRM" "C" "134" "" "")
    (COMMAND "LAYER" "MAKE" "E-ALRM-DEMO" "C" "121" "" "LT" "DASHED" "" "")
    
    ;;;add more layers here
    
    ;;reset existing layer
      (setvar "CLAYER" oldlayer)
      (setvar "cmdecho" oldcmdecho)
    (princ)
      )

  8. #8
    Login to Give a bone
    0

    Default Re: Set Linetype, Layer and start the Line command

    Thanks for your reply,
    To answer your question:
    Every engineering office operates differently as you know. Things are set up here in a way that I could not use your .lsp file. I sure like it though. What I really need is just a simple tool that I can copy for all our line types and create a button on a palette for each line type.
    The main reason I don't use the palette itself to control the properties of the line is once you draw your line and enter the properties pallette will revert back to it's orginal properties. That's not good. Because I want to place items on the line at the same color and layer.
    Can you create a .lsp file that will do just what I have listed? I can't tell you how much this will help.
    Thank you.
    Jerry
    I need a .lsp routine to set:
    Color-green
    Line type-continuous
    Layer-pipe-gas
    Weight-default
    Line type scale-1
    And
    Start the line command

  9. #9
    Login to Give a bone
    0

    Default Re: Set Linetype, Layer and start the Line command

    I changed your code to this and of course since I did it, it doesn't work.
    The only thing that changed in the properties palette was the layer name.

    Code:
    (DEFUN C:CHXX()
    	(COMMAND "-LAYER" "MAKE" "P-PIPE-AIR" "COLOR" "BYLAYER" "" "Ltype" "DASHDOT2" "" "Lweight" "DEFAULT" "" "")
            (COMMAND "LTSCALE" 1)
    	(COMMAND "PLINE" )
    Last edited by BlackBox; 2015-08-06 at 01:12 PM. Reason: Please use [CODE] Tags

  10. #10
    I could stop if I wanted to
    Join Date
    2015-05
    Location
    West Des Moines
    Posts
    306
    Login to Give a bone
    0

    Default Re: Set Linetype, Layer and start the Line command

    You also changed the color name, and that's my guess as to why it's breaking. Bylayer isn't a color choice when you're making the layer. I'll test it in a bit to see if that fixes it, but that's where I'll put my money at a glance. You'll want to go into the layer manager and pick the actual color number you want out of it and replace Bylayer with that number.

    For your understanding: that line in the code is making the layer each time you run the command so essentially what you're telling CAD to do is to make a layer with the bylayer color, which isn't a color.

    Edit:

    Unless this was a copy/paste error I see what you did. Your command doesn't work because the argument isn't closed. You're missing a parenthesize at the end of the routine. All arguments must be closed off otherwise the command doesn't know how to complete and will break/fail to load. In my experience if you load a lisp that has a command function and CAD says it's an unknown command it means the argument wasn't written properly.

    Code:
    (DEFUN C:CHXX()
    	(COMMAND "-LAYER" "MAKE" "P-PIPE-AIR" "COLOR" "Bylayer" "" "Ltype" "DASHDOT2" "" "Lweight" "DEFAULT" "" "")
            (COMMAND "LTSCALE" 1)
    	(COMMAND "PLINE" )
    )
    Note the final parenthesize at the end of my code. It closes off the very first parenthesize at the start of the routine right before the word "DEFUN". Now I'll test the bylayer theory because I don't think you can set it up that way.

    Bylayer edit: Yeah, like I expected it doesn't let you use the bylayer as a selection and says you need to pick a color number so you're better off figuring out each color number for each utility you do and putting them in from the start.
    Last edited by Varlth; 2015-08-06 at 03:39 PM.

Page 1 of 3 123 LastLast

Similar Threads

  1. Replies: 7
    Last Post: 2013-06-04, 04:01 PM
  2. Replies: 3
    Last Post: 2013-04-02, 04:11 PM
  3. Add layer command line to a lisp routine
    By BrianTFC in forum AutoLISP
    Replies: 1
    Last Post: 2012-02-02, 07:47 AM
  4. 2011: Layer Manager has me prompted at the Command Line
    By beebegs in forum AutoCAD General
    Replies: 14
    Last Post: 2011-04-13, 02:04 PM
  5. Offset command - New Line to be on current layer
    By neilcheshire in forum AutoCAD General
    Replies: 8
    Last Post: 2005-06-17, 11:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •