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: 21.Feb.2011 at 22:11
Hi.  Someone helped me with this, but I'm not able to get it to run. It has a syntax error.
[CODE]
(defun C:NEWL ();R-1
(vl-load-com);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
);R-0
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: 21.Feb.2011 at 23:27
The initial error I got was "ERROR: malformed string on input".

By changing Line7 to the following, it cleared that error, but every time I enter a suffix type, I now get the error: "Invalid Option Keyword"

(princ (strcat ObjLayer " is layer name of " ObjType " selected"));R-1


NOTE: You were missing a " (quote) between ObjLayer and is.


Edited by HAWDesigner - 21.Feb.2011 at 23:29
--
R. Williams
AutoCAD 2010 Certified Professional
<!-- If all else fails hit F1 -->
<<AutoCAD 2009
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: 22.Feb.2011 at 01:43
Thanks.  So if I wanted to create a new layer based on the entity that I selected (for instance a line on H-ROOM layer), how would I attach the modifier to that entity so that if I choose D for suffix, it will automatically create a new layer based on the entity so that the new layer would look like this: H-ROOM-D-PKG1?  Thanks.
 
(Setq LyrSuffix (getkword "\nEnter suffix type [N-PKG-1/D-PKG1/V-PKG-1]:"))
 
Would it be something like this..?
 
      (setq oLayers
      (vla-get-layers
        (vla-get-activedocument
   (vlax-get-acad-object))))
(if (not (tblsearch "LAYER" objlayer))
       (progn 
         (setq LyrNew (vla-add oLayers LYR)
        LyrTab (vla-item oLayers sLYR)
        )
  (vla-put-linetype LyrNew (vla-get-linetype LyrTab))
  (vla-put-truecolor LyrNew (vla-get-truecolor LyrTab))
  (vla-put-truecolor LyrNew (vla-get-truecolor LyrTab))
  (vla-put-freeze LyrNew (vla-get-freeze LyrTab))
  (vla-put-layeron LyrNew (vla-get-layeron LyrTab))
  (vla-put-lineweight LyrNew (vla-get-lineweight LyrTab))
  (vla-put-lock LyrNew (vla-get-lock LyrTab))
  (vla-put-material LyrNew (vla-get-material LyrTab))
  ;(vla-put-plotstylename LyrNew (vla-get-plotstylename LyrTab))
  ))
(setq ent (car(entsel)))
(setq nlayer
(cdr (assoc 8 (entget ent)))
)
(setq LyrNew (strcat LYR lyrsuffix))


Edited by kameron1967 - 22.Feb.2011 at 01:50
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: 22.Feb.2011 at 14:00
I'm not an expert on LISP yet, sorry. Finding syntax errors is about as far as my LISP abilities go. Perhaps CarlB can lend you a hand on this.

Good Luck!!
--
R. Williams
AutoCAD 2010 Certified Professional
<!-- If all else fails hit F1 -->
<<AutoCAD 2009
Back to Top
Vladimir Michl View Drop Down
Moderator Group
Moderator Group

Arkance Systems CZ

Joined: 26.Jul.2007
Location: Czech Republic
Using: Autodesk software
Status: Offline
Points: 2124
Direct Link To This Post Posted: 22.Feb.2011 at 14:58
Yes, this is one of the ways how to do it. This LISP code seems to be mixed from several sources - the names of layer variables are mixed: objlayer, LYR, nlayer.
 
Assumes e.g. that objlayer is already filled with the old layer name.
Vladimir Michl (moderator)
ARKANCE - https://arkance.world - Autodesk Platinum Partner
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: 22.Feb.2011 at 18:00

yes, you're right.  It was taken from various source.  I need to somehow tie them all in so that whatever letter I choose, it appends the right suffix to the new layer that it will be creating.

If anyone has a shortcut to creating a simple layer modifer, I'd love to see it.  Basically, if N is chosen, it will add the -N-PKG1 in the new layer based on the entity selected.  Thanks.
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 02:06
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
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 02:24
Thanks, CarlB.  You're a savior!
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
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

Related CAD tips:


 Post Reply Post Reply Page  12>
  Share Topic   

Forum Jump Forum Permissions View Drop Down



This page was generated in 0,340 seconds.