See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Create layer lisp problem in R2012

  1. #1
    Login to Give a bone
    0

    Default Create layer lisp problem in R2012

    Hi Guys,

    I’ve got a lisp routine that creates a layer, sets the color, weight and specially the description.
    It works perfectly in AutoCAD2010. Now I’m upgrading to AutoCAD 2012 and the program will not work….

    Can anybody help my, with correcting my program, or sharing another working one?


    Code:
    (defun CreateLayer (Name FrzLock Color LType Plot LWeight Desc)
      (entmakex
        (list (cons 0 "LAYER")
      (cons 100 "AcDbSymbolTableRecord")
      (cons 100 "AcDbLayerTableRecord")
      (cons 2 Name)
      (cons 70 FrzLock)
      (cons 62 Color)
      (cons 6 LType)
      (cons 290 Plot)
      (cons 370 LWeight)
      (list -3 (list "AcAecLayerStandard" (cons 1000 "") (cons 1000 Desc)))
        )
      )
      (setvar "CLAYER" Name)
    )


    Thank you,
    Marc
    Last edited by rkmcswain; 2012-12-03 at 07:53 PM. Reason: added [CODE] tags

  2. #2
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Default Re: Create layer lisp problem in R2012

    Works fine here in 2013.
    Make sure you are not trying to reference something that doesn't exist. For example, you can't create a new layer and set the HIDDEN linetype to it, if HIDDEN is not loaded.
    R.K. McSwain | CAD Panacea |

  3. #3
    Login to Give a bone
    0

    Default Re: Create layer lisp problem in R2012

    the keyin I've used:

    Code:
    (CreateLayer "54_00-P" 0 50 "continuous" 1 50 "Gas general (primary)")
    and that doesn't do it!
    Last edited by RenderMan; 2012-12-03 at 10:37 PM. Reason: Please use [CODE] tags

  4. #4
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Default Re: Create layer lisp problem in R2012

    Your function worked fine here in 2013.

    While you're in ACAD, type in VLIDE.
    In this window, ppen a new file, then paste your code in.
    Below that, outside the (defun), paste in your function above.
    Now load all the code in the window (Ctrl+Alt+E)

    This should at least point you to the line where it's failing.
    R.K. McSwain | CAD Panacea |

  5. #5
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Create layer lisp problem in R2012

    It did not work either due to the description , I removed the description and it did work .

  6. #6
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Create layer lisp problem in R2012

    I guess this way works better ..

    Code:
    (defun CreateLayer (Name FrzLock Color LType Plot LWeight)
      (entmakex (list (cons 0 "LAYER")
                      (cons 100 "AcDbSymbolTableRecord")
                      (cons 100 "AcDbLayerTableRecord")
                      (cons 2 Name)
                      (cons 70 FrzLock)
                      (cons 62 Color)
                      (cons 6 LType)
                      (cons 290 Plot)
                      (cons 370 LWeight)
                )
      )
    )
    (if (setq l (CreateLayer "54_00-P" 0 50 "continuous" 1 50))
      (progn (vla-put-Description (vlax-ename->vla-object l) "Gas general (primary)")
             (setvar "CLAYER" "54_00-P")
      )
    )
    (vl-load-com)

  7. #7
    Login to Give a bone
    0

    Default Re: Create layer lisp problem in R2012

    I also found the problem is in the description.
    The description is the most important part of this code.

    On the other hand, I need to be able to use this code with variables. I need to create layers from the tool pallet so that's why I want to code to use something like:

    (CreateLayer "layername" 0 50 "continuous" 1 50 "description")

    What I can’t understand is why it worked in R2010 and not in R2012. The code is the same…..

  8. #8
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Create layer lisp problem in R2012

    Quote Originally Posted by marc.verdaasdonk697335 View Post
    I need to be able to use this code with variables. I need to create layers from the tool pallet so that's why I want to code to use something like:

    (CreateLayer "layername" 0 50 "continuous" 1 50 "description")
    So here it goes ....

    Code:
    (defun CreateLayer (Name FrzLock Color LType Plot LWeight Desc)
      (setq l (entmakex (list (cons 0 "LAYER")
                              (cons 100 "AcDbSymbolTableRecord")
                              (cons 100 "AcDbLayerTableRecord")
                              (cons 2 Name)
                              (cons 70 FrzLock)
                              (cons 62 Color)
                              (cons 6 LType)
                              (cons 290 Plot)
                              (cons 370 LWeight)
                        )
              )
      )
      (if l
        (progn (vla-put-Description (vlax-ename->vla-object l) Desc) (setvar "CLAYER" Name))
      )
    )
    (vl-load-com)
    Code:
    (CreateLayer "54_00-P" 0 50 "continuous" 1 50 "Gas general (primary)")
    EDIT : Name of Layer were written instead of the variable name
    Last edited by Tharwat; 2012-12-04 at 10:16 AM.

  9. #9
    Login to Give a bone
    0

    Default Re: Create layer lisp problem in R2012

    This is very close!

    Only thing is that I use the lisp in a menu. This menu is also used to control the layers. So it will happen that the code is used to activate a layer.
    This doesn't work now.

    So is it possible to change the code that the layer gets active when it already excists.

  10. #10
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Create layer lisp problem in R2012

    Uhmm ... setvar the CLayer to the new layer's name perhaps? Like you had in the old one's last line?

    BTW, what should happen if the layer already exists? Should the properties be updated, or left as is?

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 6
    Last Post: 2021-09-17, 06:21 PM
  2. LISP to create layer, hatch and set layer back to original.
    By jpcadconsulting347236 in forum AutoLISP
    Replies: 1
    Last Post: 2013-12-11, 07:22 PM
  3. Ability to Create a Layer that Acts Similar to Layer 0
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2008-05-28, 06:58 PM
  4. Lisp routine help, Layer check problem
    By Craig.Baldie in forum AutoLISP
    Replies: 6
    Last Post: 2007-10-12, 06:27 AM
  5. Replies: 3
    Last Post: 2007-03-14, 01:33 PM

Posting Permissions

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