CAD Forum - tips, tricks, discussion and utilities for AutoCAD, Inventor, Revit and other Autodesk products [www.cadforum.cz] ARKANCE | CONTACT - CZ | SK | EN | DE
RSS channel - CAD tips RSS tips
RSS discussions

Discussion Discussion forum

?
CAD discussions, advices, exchange of experience

CAD Forum - Homepage CAD discussion forum - ask any CAD-related questions here, share your CAD knowledge on AutoCAD, Inventor, Revit and other Autodesk software with your peers from all over the world. To start a new topic, choose an appropriate forum.

Please abide by the rules of this forum.
This is a peer-to-peer forum. The forum doesn't replace the official direct technical support provided by ARKANCE for its customers.
How to post questions: register or login, go to the specific forum and click the NEW TOPIC button.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Topic ClosedLISP Error

 Post Reply Post Reply Page  12>
Author
kameron1967 View Drop Down
Groupie
Groupie


Joined: 30.Jan.2011
Location: United States
Using: autocad 2018
Status: Offline
Points: 29
Direct Link To This Post Topic: LISP Error
    Posted: 01.Mar.2011 at 22:04
CarlB,
 
This is the solution.  In addition to the code shown below, the lineweight needs to be 13 instead of 0.13.
 
Thanks though for your valuable help.  I really appreciate your help in this.
 
[code]
 
(setq
LyrEdata (entget (tblobjname "Layer" ObjLayer))
LyrWeight (cdr (assoc 370 LyrEdata))
)
((= LyrSuffix "X") (setq NewLyrName (strcat ObjLayer "-X-PKG-1"))
(setq LyrLtype "PHANTOM") (setq LyrColor "8") (setq LyrWeight 53)) )

(command "-Layer" "_M" NewLyrname "_C" LyrColor "" "_L" LyrLtype "" "LW" (if (= LyrWeight -3) "D" (/ LyrWeight 100.0)) "" "")
(princ)
)
(princ "\n<!> Type {LAX} and choose your layer modifier <!>")
Back to Top
CarlB View Drop Down
Senior Member
Senior Member


Joined: 16.Oct.2009
Location: United States
Status: Offline
Points: 321
Direct Link To This Post Posted: 01.Mar.2011 at 07:44
Your idea is sound, extracting default data, overriding it later if desired. Since i don't have AutoCADd to check, not sure the 370 code & tblsearch will give you lineweight, or if so will be the correct format to feed back to the "layer" command. You can give me an update on that :)
 
(defun C:NEWL ();R-1, R-2 to reproduce layer settings 2/23/11
   (setq PickItem (car (entsel "\nPick object for new layer: ")));R-1
   (setq Entdata (entget pickItem))   (setq ObjLayer (cdr (assoc 8 EntData)));R-1
   (setq ObjType (cdr (assoc 0 EntData)));R-1   (princ (strcat ObjLayer " is layer name of " ObjType " selected"));R-1
   (setq Lyrdata (tblsearch "LAYER" ObjLayer));R-2
   (setq LyrLtype (cdr (assoc 6 Lyrdata)));R-2
   (setq LyrColor (cdr (assoc 62 Lyrdata)));R-2
   (setq LyrWeight (cdr (assoc 370 Lyrdata)));;R-3
   (initget "N D V X");R-1
   (setq LyrSuffix (getkword "\nEnter suffix type [N-PKG-1/D-PKG1/V-PKG-1/X-PKG-1]:"));R-1
   (cond
       ((= LyrSuffix "N")
            (setq NewLyrName (strcat ObjLayer "-N-PKG-1"))
        )
       ((= LyrSuffix "D")
              (setq NewLyrName (strcat ObjLayer "-D-PKG-1"))
        )
       ((= LyrSuffix "V")
              (setq NewLyrName (strcat ObjLayer "-V-PKG-1"))
        )
       ((= LyrSuffix "X");;R-3
              (setq NewLyrName (strcat ObjLayer "-X-PKG-1"))
              (setq LyrLtype "PHANTOM")
              (setq LyrColor "8")
              (setq LyrWeight "0.13")
              
        )
   )
   (command "._Layer" "_M" NewLyrname "_C" LyrColor "" "_L" LyrLtype "_LW" LyrWeight "" "");R-2&3
   (princ)
)


Edited by CarlB - 01.Mar.2011 at 07:44
Back to Top
kameron1967 View Drop Down
Groupie
Groupie


Joined: 30.Jan.2011
Location: United States
Using: autocad 2018
Status: Offline
Points: 29
Direct Link To This Post Posted: 28.Feb.2011 at 21:07
CarlB - there are some layers that require different lineweight to be defined, where the rest uses whatever was assigned in the original layer.  I thought if I just set the variable for the lineweight on the layer table, it will default to that, unless I specified it as shown below:
 
 
(setq Lyrdata (tblsearch "LAYER" ObjLayer));R-2  
(setq LyrLtype (cdr (assoc 6 Lyrdata)));R-2  
(setq LyrColor (cdr (assoc 62 Lyrdata)));R-2  
(setq Lyrweight (cdr (assoc 370 Lyrdata)));R-2   (LINEWEIGHT)
 
        ((= LyrSuffix "X")
(setq LyrLtype "sphantom")
(setq LyrColor "8")
(setq Lyrweight "0.13")
 (strcat ObjLayer "-X-D1C1270" ));R-3

       );R-2

    );R-1

(command "-Layer" "_M" NewLyrname "_C" LyrColor "" "_L" LyrLtype "_lw" Lyrweight "" "");R-2   ADDED LINEWEIGHT HERE AS WELL



Edited by kameron1967 - 01.Mar.2011 at 00:23
Back to Top
CarlB View Drop Down
Senior Member
Senior Member


Joined: 16.Oct.2009
Location: United States
Status: Offline
Points: 321
Direct Link To This Post Posted: 28.Feb.2011 at 21:03

I think we have more to work out...

I had thought you were just assigning a lineweight to a layer with this code, so the variable name could be whatever you want to call it, then that same variable name would be used later in the command to define the new layer:
(command ".-layer" etc.... "_LW" lyrweight etc...)
 
It you want to assign the same layer weight as object layer selected, will need some other steps...
Back to Top
kameron1967 View Drop Down
Groupie
Groupie


Joined: 30.Jan.2011
Location: United States
Using: autocad 2018
Status: Offline
Points: 29
Direct Link To This Post Posted: 28.Feb.2011 at 20:34
Thanks, CarlB.  I was trying so hard to find the LYRweight variable.  I tried LYRLW, LYRLWEIGHT, but couldn't get it to work.  I kind of makes sense for the variable to be called LYRweight, but I would never have guessed it.  Once again, you're my savior!
 
One last question:  What is the lyrweight number?  I never know where to find this info (see below).  Thanks.
 
(setq Lyrdata (tblsearch "LAYER" ObjLayer));R-2  
(setq LyrLtype (cdr (assoc 6 Lyrdata)));R-2  
(setq LyrColor (cdr (assoc 62 Lyrdata)));R-2  

(setq Lyrweight (cdr (assoc ?? Lyrdata)));R-2  
 
Big%20smile


Edited by kameron1967 - 28.Feb.2011 at 21:02
Back to Top
CarlB View Drop Down
Senior Member
Senior Member


Joined: 16.Oct.2009
Location: United States
Status: Offline
Points: 321
Direct Link To This Post Posted: 28.Feb.2011 at 20:02
Well the 'cond' was a subfunction of a 'setq layer' so you should rearrange like below to add more 'setqs' to the cond:
 
(cond
  ((= LyrSuffix "A")
     (setq xxxlayer (strcat ObjLayer "-A-D1C1270" ))
    (setq lyrcolor "1")
   (setq lyrltype "continuous")
   (setq lyrweight "0.25")
);R-3
 
-or shorter versio-
 
(cond
  ((= LyrSuffix "A")
     (setq xxxlayer (strcat ObjLayer "-A-D1C1270" )
    lyrcolor "1"
    lyrltype "continuous"
   lyrweight "0.25"
);R-3
 
Back to Top
kameron1967 View Drop Down
Groupie
Groupie


Joined: 30.Jan.2011
Location: United States
Using: autocad 2018
Status: Offline
Points: 29
Direct Link To This Post Posted: 28.Feb.2011 at 19:06
CarlB,
 
Sorry to keep bothering you.  But if I wanted to also include lineweight, but have the ability to modify each aspect of the layer color, linetype and lineweight within the selected suffix - for instance D, can I specify the layer information within the parenthesis?  See below.  Thanks.
 
        ((= LyrSuffix "A")
(setq LyrLtype "sphantom")
(setq LyrColor "1")
;(setq LyrLw "0.25") - what's the variable for lineweight?
(strcat ObjLayer "-A-D1C1270" ))
 
  


Edited by kameron1967 - 28.Feb.2011 at 20:13
Back to Top
CarlB View Drop Down
Senior Member
Senior Member


Joined: 16.Oct.2009
Location: United States
Status: Offline
Points: 321
Direct Link To This Post Posted: 23.Feb.2011 at 19:50
Revised to take on layer color & linetype. no checking for locked status, etc.  Enjoy!
 
(defun C:NEWL ();R-1, R-2 to reproduce layer settings 2/23/11
   (setq PickItem (car (entsel "\nPick object for new layer: ")));R-1
   (setq Entdata (entget pickItem))
   (setq ObjLayer (cdr (assoc 8 EntData)));R-1
   (setq ObjType (cdr (assoc 0 EntData)));R-1
   (princ (strcat ObjLayer " is layer name of " ObjType " selected"));R-1
   (setq Lyrdata (tblsearch "LAYER" ObjLayer));R-2
   (setq LyrLtype (cdr (assoc 6 Lyrdata)));R-2
   (setq LyrColor (cdr (assoc 62 Lyrdata)));R-2
   (initget "N D V");R-1
   (Setq LyrSuffix (getkword "\nEnter suffix type [N-PKG-1/D-PKG1/V-PKG-1]:"));R-1
   (setq NewLyrName
      (cond
        ((= LyrSuffix "N") (strcat ObjLayer "-N-PKG-1" ))
        ((= LyrSuffix "D") (strcat ObjLayer "-D-PKG-1"))
        ((= LyrSuffix "V") (strcat ObjLayer "-V-PKG-1"))
      )
   )
   (command "._Layer" "_M" NewLyrname "_C" LyrColor "" "_L" LyrLtype "" "");R-2
   (princ)
)
Back to Top
kameron1967 View Drop Down
Groupie
Groupie


Joined: 30.Jan.2011
Location: United States
Using: autocad 2018
Status: Offline
Points: 29
Direct Link To This Post Posted: 23.Feb.2011 at 17:48
CarlB - is there a way to make it so that the newly created layer of the entity that we selected retains that same layer information as the one entity that we selected?  As of right now, it creates a new layer, but with default color and linetype.  If we can specify the linetype and color associated to each modifier, that would work also.  Thanks.
 
Originally posted by CarlB CarlB wrote:

OK since my name was mentioned..here's my take at a simple lisp..
 

(defun C:NEWL ();R-1
   (setq PickItem (car (entsel "\nPick object for new layer: ")));R-1
   (setq ObjLayer (cdr (assoc 8 (entget pickItem))));R-1
   (setq ObjType (cdr (assoc 0 (entget pickItem))));R-1
   (princ (strcat ObjLayer " is layer name of " ObjType " selected"));R-1
   (initget "N D V");R-1
   (Setq LyrSuffix (getkword "\nEnter suffix type [N-PKG-1/D-PKG1/V-PKG-1]:"));R-1
   (setq NewLyrName
      (cond
         ((= LyrSuffix "N") (strcat ObjLayer "-N-PKG-1" ))
         ((= LyrSuffix "D") (strcat ObjLayer "-D-PKG-1"))
         ((= LyrSuffix "V") (strcat ObjLayer "-V-PKG-1"))
       )
    )
    (command "._Layer" "_M" NewLyrname "")
   (princ)
)
Back to Top
HAWDesigner View Drop Down
Senior Member
Senior Member


Joined: 04.Aug.2008
Location: United States
Using: AutoCAD R14, AutoCAD 2009, AutoCAD 2010
Status: Offline
Points: 310
Direct Link To This Post Posted: 23.Feb.2011 at 15:26
Nice Carl, thanks for that. I hope I didn't throw you under the bus there. Shocked

Here's something I noticed in v2009:

(Setq LyrSuffix (getkword "\nEnter suffix type [N-PKG-1/D-PKG1/V-PKG-1]:"));R-1


The code above results in an error if you select the value from the Drafting ToolTips.



... because it is entering the entire value instead of just the N, D, or V as the "(initget "N D V");R-1" requests.

In order to prevent that error, I had to change the line to the following, but I know that doesn't fully explain what's going on.

(Setq LyrSuffix (getkword "\nEnter suffix type [N/D/V]:"));R-1



Is there any way to have it both ways?


Edited by HAWDesigner - 23.Feb.2011 at 15:27
--
R. Williams
AutoCAD 2010 Certified Professional
<!-- If all else fails hit F1 -->
<<AutoCAD 2009
Back to Top

Related CAD tips:


 Post Reply Post Reply Page  12>
  Share Topic   

Forum Jump Forum Permissions View Drop Down



This page was generated in 0,090 seconds.