+ Reply to Thread
Page 3 of 3 FirstFirst 1 2 3
Results 21 to 30 of 30
  1. #21
    Full Member
    Using
    AutoCAD 2016
    Join Date
    Aug 2016
    Posts
    31

    Question Why the error?

    Registered forum members do not see this ad.

    No matter what I try, i keep getting an "Invalid Option Keyword". Here is what i have so far. don't know why i can't make it work.

    Code:
    (defun c:px2 ( / cmd ent enx ped pw1 pkw )
        (setvar 'errno 0)
        (while (/= 52 (getvar 'errno))
            (setvar 'errno 0)
            (setq ent (car (entsel "\nSelect polyline <exit>: ")))
            (cond
                (   (= 7 (getvar 'errno))
                    (prompt "\nMissed, try again.")
                )
                (   (null ent)
                    (prompt "\nExit.")
                )
                (   (/= "LWPOLYLINE" (cdr (assoc 0 (setq enx (entget ent)))))
                    (prompt "\nSelected object is not an LWPolyline.")
                )
                (   (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (cdr (assoc 8 enx)))))))
                    (prompt "\nSelected polyline is on a locked layer.")
                )
                (   (setq cmd (getvar 'cmdecho)
                          ped (getvar 'peditaccept)
                    )
                    (setvar 'cmdecho 0)
                    (setvar 'peditaccept 1)
    		(if (= (cdr (assoc 43 enx)) nil)
    			(if (= (cdr (assoc 41 enx)) (cdr (assoc 40 enx)))
    				(setq pw1 (cdr (assoc 40 enx)))
    				((initget "Start End")
    				 (setq pkw (getkword "\nMatch Starting or Ending Width? [Start/End]: "))
    					(cond
    						((= pkw "S") (setq pw1 (cdr (assoc 40 enx))))
    						((= pkw "E") (setq pw1 (cdr (assoc 41 enx))))
    					)
    				)
    			)
    			(setq pw1 (cdr (assoc 43 enx)))
    		)
                    (command
                        "_.explode" ent
                        "_.pedit" "_m" "_p" "" "_w" pw1 ""
                    )
                    (setvar 'peditaccept ped)
                    (setvar 'cmdecho cmd)
                )
            )
        )
        (princ)
    )
    I'm able to click on Start or End, but doing so will give me the error. I've also tried typing S s E e Start START End END but i keep getting the error.
    I've also tried localizing the strings i.e.
    Code:
    (initget "Start End _(cdr (assoc 40 enx)) (cdr (assoc 41 enx))")
    but that also doesn't allow any option to be correct. same error no matter what i type.

    I'm all out of ideas.

  2. #22
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,073

    Default

    Try the following (modified RED code fragment from your post) :
    Code:
    (if (= (cdr (assoc 43 enx)) nil)
    	(if (= (cdr (assoc 41 enx)) (cdr (assoc 40 enx)))
    		(setq pw1 (cdr (assoc 40 enx)))
    		(progn
    			(initget "Start End S E")
    			(setq pkw (strcase (getkword "\nMatch Starting or Ending Width? [Start/End]: ")))
    			(cond
    				((or (= pkw "START")(= pkw "S")) (setq pw1 (cdr (assoc 40 enx))))
    				((or (= pkw "END")(= pkw "E")) (setq pw1 (cdr (assoc 41 enx))))
    			)
    		); progn
    	)
    	(setq pw1 (cdr (assoc 43 enx)))
    )

  3. #23
    Super Member
    Using
    not applicable
    Join Date
    Jun 2016
    Posts
    531

    Default

    @ Grrr:
    Your use of (initget ...) is not correct.
    See:
    http://docs.autodesk.com/ACD/2011/EN...b7ccc-69da.htm

    Note that (getkword ...) can also return nil.
    BricsCAD 16

  4. #24
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,073

    Default

    Quote Originally Posted by Roy_043 View Post
    @ Grrr:
    Your use of (initget ...) is not correct.
    See:
    http://docs.autodesk.com/ACD/2011/EN...b7ccc-69da.htm

    Note that (getkword ...) can also return nil.
    Thanks, I was sure about that.. so I rely on the (cond) below it. Its not the first time I do this mistake, I'm just lazy to analyse this particular problem.

  5. #25
    Full Member
    Using
    AutoCAD 2016
    Join Date
    Aug 2016
    Posts
    31

    Default

    Quote Originally Posted by Grrr View Post
    Try the following (modified RED code fragment from your post)
    Wow, that worked great! The lisp is now complete!

    I'll need to study how you did it and learn from it! Thanks

    To anyone that runs into this thread looking for a fail-proof way to "Unjoin a polyline" "explode a polyline while keeping the width"

    here is the Lisp
    Code:
    (defun c:px ( / cmd ent enx ped pw1 pkw )
        (setvar 'errno 0)
        (while (/= 52 (getvar 'errno))
            (setvar 'errno 0)
            (setq ent (car (entsel "\nSelect polyline <exit>: ")))
            (cond
                (   (= 7 (getvar 'errno))
                    (prompt "\nMissed, try again.")
                )
                (   (null ent)
                    (prompt "\nExit.")
                )
                (   (/= "LWPOLYLINE" (cdr (assoc 0 (setq enx (entget ent)))))
                    (prompt "\nSelected object is not an LWPolyline.")
                )
                (   (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (cdr (assoc 8 enx)))))))
                    (prompt "\nSelected polyline is on a locked layer.")
                )
                (   (setq cmd (getvar 'cmdecho)
                          ped (getvar 'peditaccept)
                    )
                    (setvar 'cmdecho 0)
                    (setvar 'peditaccept 1)
    		(if (= (cdr (assoc 43 enx)) nil)
    			(if (= (cdr (assoc 41 enx)) (cdr (assoc 40 enx)))
    				(setq pw1 (cdr (assoc 40 enx)))
    					(progn
    						(initget "Start End S E")
    						(setq pkw (strcase (getkword "\nMatch Starting or Ending Width? [Start/End]: ")))
    				(cond
    				((or (= pkw "START")(= pkw "S")) (setq pw1 (cdr (assoc 40 enx))))
    				((or (= pkw "END")(= pkw "E")) (setq pw1 (cdr (assoc 41 enx))))
    			)
    		); progn
    	)
    	(setq pw1 (cdr (assoc 43 enx)))
    )
                    (command
                        "_.explode" ent
                        "_.pedit" "_m" "_p" "" "_w" pw1 ""
                    )
                    (setvar 'peditaccept ped)
                    (setvar 'cmdecho cmd)
                )
            )
        )
        (princ)
    )

  6. #26
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,073

    Default

    Quote Originally Posted by RubberDinero View Post
    Wow, that worked great! The lisp is now complete!

    I'll need to study how you did it and learn from it! Thanks
    You're wellcome. For a quick/successful start with LISP I would suggest you to read/practice with these functions: if , cond , and , or , not , eq , while , repeat
    So later you would know how to properly structure your codes (by using functions for getting user input - like getkword/getstring/getpoint/getreal ...)
    ... and manipulating it.

  7. #27
    Super Member
    Using
    not applicable
    Join Date
    Jun 2016
    Posts
    531

    Default

    @ Grrr: you are missing several issues.
    For one thing your code cannot cope with a nil return from (getkword). It would crash as (strcase) expects string input. And, contrary to what you say, your (cond) does not have a statement to handle pkw=nil, which would be required since the rest of the code relies on a valid value for pw1.
    Code:
    (progn
      (initget "Start End")
      (if (= "End" (getkword "\nMatch Starting or Ending Width? End/<Start>: "))
        (setq pw1 (cdr (assoc 41 enx))) ; User entered "E", "e", "end", "EN" or ... (no need for strcase).
        (setq pw1 (cdr (assoc 40 enx))) ; User pressed Enter or entered "S", "s", "start", "STA" or ...
      )
    )
    BricsCAD 16

  8. #28
    Full Member
    Using
    AutoCAD 2016
    Join Date
    Aug 2016
    Posts
    31

    Default

    Quote Originally Posted by Roy_043 View Post
    Code:
    (progn
      (initget "Start End")
      (if (= "End" (getkword "\nMatch Starting or Ending Width? End/<Start>: "))
        (setq pw1 (cdr (assoc 41 enx))) ; User entered "E", "e", "end", "EN" or ... (no need for strcase).
        (setq pw1 (cdr (assoc 40 enx))) ; User pressed Enter or entered "S", "s", "start", "STA" or ...
      )
    )
    That did work even better! I tried Grrr's code by just pressing "Enter" and it did fail. with your code, I modified the wording a bit, it defaults to Starting by pressing enter.
    Code:
    (defun c:px2 ( / cmd ent enx ped pw1 pkw pwt )
        (setvar 'errno 0)
        (while (/= 52 (getvar 'errno))
            (setvar 'errno 0)
            (setq ent (car (entsel "\nSelect polyline <exit>: ")))
            (cond
                (   (= 7 (getvar 'errno))
                    (prompt "\nMissed, try again.")
                )
                (   (null ent)
                    (prompt "\nExit.")
                )
                (   (/= "LWPOLYLINE" (cdr (assoc 0 (setq enx (entget ent)))))
                    (prompt "\nSelected object is not an LWPolyline.")
                )
                (   (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (cdr (assoc 8 enx)))))))
                    (prompt "\nSelected polyline is on a locked layer.")
                )
                (   (setq cmd (getvar 'cmdecho)
                          ped (getvar 'peditaccept)
                    )
                    (setvar 'cmdecho 0)
                    (setvar 'peditaccept 1)
    		(if (= (cdr (assoc 43 enx)) nil)
    			(if (= (cdr (assoc 41 enx)) (cdr (assoc 40 enx)))
    				(setq pw1 (cdr (assoc 40 enx)))
    					(progn
    					  (initget "Start End")
    					  (if (= "End" (getkword "\nMatch Starting or Ending Width? [Start/End]:<Start> "))
    					    (setq pw1 (cdr (assoc 41 enx))) ; User entered "E", "e", "end", "EN" or ... (no need for strcase).
    					    (setq pw1 (cdr (assoc 40 enx))) ; User pressed Enter or entered "S", "s", "start", "STA" or ...
    					  )
    					)
    	)
    	(setq pw1 (cdr (assoc 43 enx)))
    )
                    (command
                        "_.explode" ent
                        "_.pedit" "_m" "_p" "" "_w" pw1 ""
                    )
                    (setvar 'peditaccept ped)
                    (setvar 'cmdecho cmd)
                )
            )
        )
        (princ)
    )

  9. #29
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,073

    Default

    Quote Originally Posted by Roy_043 View Post
    @ Grrr: you are missing several issues.
    For one thing your code cannot cope with a nil return from (getkword). It would crash as (strcase) expects string input. And, contrary to what you say, your (cond) does not have a statement to handle pkw=nil, which would be required since the rest of the code relies on a valid value for pw1.
    Code:
    (progn
      (initget "Start End")
      (if (= "End" (getkword "\nMatch Starting or Ending Width? End/<Start>: "))
        (setq pw1 (cdr (assoc 41 enx))) ; User entered "E", "e", "end", "EN" or ... (no need for strcase).
        (setq pw1 (cdr (assoc 40 enx))) ; User pressed Enter or entered "S", "s", "start", "STA" or ...
      )
    )
    Thanks for the constructive criticism Roy,
    Perhaps I don't analyse deep enough the solutions I'm posting (usually I use initget with bit 1 to prevent user from pressing ENTER). Your example seems perfect for this case, however I try to avoid using if within initget, and use instead (practice with) cond - just in case we would had more than 2 options:
    Code:
    (defun c:test ( / sUndo cmd ent enx ped pw1 pkw pwt *ans*)
    	(setq sUndo (vlax-invoke (vla-get-ActiveDocument (vlax-get-acad-object)) 'StartUndoMark))
    	(setvar 'errno 0)
    	(while (/= 52 (getvar 'errno))
    		(setvar 'errno 0)
    		(setq ent (car (entsel "\nSelect polyline <exit>: ")))
    		(cond
    			(   (= 7 (getvar 'errno))
    				(prompt "\nMissed, try again.")
    			)
    			(   (null ent)
    				(prompt "\nExit.")
    			)
    			(   (/= "LWPOLYLINE" (cdr (assoc 0 (setq enx (entget ent)))))
    				(prompt "\nSelected object is not an LWPolyline.")
    			)
    			(   (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (cdr (assoc 8 enx)))))))
    				(prompt "\nSelected polyline is on a locked layer.")
    			)
    			(   (setq cmd (getvar 'cmdecho)
    				ped (getvar 'peditaccept)
    			)
    			(setvar 'cmdecho 0)
    			(setvar 'peditaccept 1)
    			(if (not (assoc 43 enx))
    				(cond
    					((= (cdr (assoc 41 enx)) (cdr (assoc 40 enx)))
    						(setq pw1 (cdr (assoc 40 enx)))
    					)
    					(T
    						(or *ans* (setq *ans* "Starting")) ; Used http://www.lee-mac.com/promptwithdefault.html Dynamic Default Version2
    						(initget "Starting Ending Value") 
    						(setq *ans* (cond ((getkword (strcat "\nMatch Starting or Ending Width or specify a Value [Start/End/Value] ? <" *ans* ">: "))) ( *ans* )))
    						(cond
    							((wcmatch *ans* "S*")
    								(setq pw1 (cdr (assoc 40 enx)))
    							)
    							((wcmatch *ans* "E*")
    								(setq pw1 (cdr (assoc 41 enx)))
    							)
    							((wcmatch *ans* "V*")
    								(initget (+ 1 4))
    								(setq pw1 (getreal "\nSpecify width value: "))
    							)
    						)
    					)
    				)
    				(setq pw1 (cdr (assoc 43 enx)))
    			)
    			(if pw1 
    				(command
    					"_.explode" ent
    					"_.pedit" "_m" "_p" "" "_w" pw1 ""
    				)
    			)
    			(setvar 'peditaccept ped)
    			(setvar 'cmdecho cmd)
    			)
    		)
    	)
    	(if sUndo (vlax-invoke (vla-get-ActiveDocument (vlax-get-acad-object)) 'EndUndoMark))
    	(princ)
    )(vl-load-com)(princ)
    Lee mac's website always come to the rescue.

  10. #30
    Full Member
    Using
    AutoCAD 2016
    Join Date
    Aug 2016
    Posts
    31

    Default

    Registered forum members do not see this ad.

    Grrr!!! your new code made possible what i had in mind! but i felt i had already overstepped my welcome with request! But thanks to your latest response, i was able to add what i wanted to add but was getting error-ed out.

    Code:
    (defun c:px2 ( / sUndo cmd ent enx ped pw1 pkw *ans*)
    	(setq sUndo (vlax-invoke (vla-get-ActiveDocument (vlax-get-acad-object)) 'StartUndoMark))
    	(setvar 'errno 0)
    	(while (/= 52 (getvar 'errno))
    		(setvar 'errno 0)
    		(setq ent (car (entsel "\nSelect polyline <exit>: ")))
    		(cond
    			(   (= 7 (getvar 'errno))
    				(prompt "\nMissed, try again.")
    			)
    			(   (null ent)
    				(prompt "\nExit.")
    			)
    			(   (/= "LWPOLYLINE" (cdr (assoc 0 (setq enx (entget ent)))))
    				(prompt "\nSelected object is not an LWPolyline.")
    			)
    			(   (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (cdr (assoc 8 enx)))))))
    				(prompt "\nSelected polyline is on a locked layer.")
    			)
    			(   (setq cmd (getvar 'cmdecho)
    				ped (getvar 'peditaccept)
    			)
    			(setvar 'cmdecho 0)
    			(setvar 'peditaccept 1)
    			(if (not (assoc 43 enx))
    				(cond
    					((= (cdr (assoc 41 enx)) (cdr (assoc 40 enx)))
    						(setq pw1 (cdr (assoc 40 enx)))
    					)
    					(T
    						(or *ans* (setq *ans* "Starting")) ; Used http://www.lee-mac.com/promptwithdefault.html Dynamic Default Version2
    						(initget "Starting Ending Value") 
    						(setq *ans* (cond ((getkword
    (strcat "\nStarting Width is " (rtos (cdr (assoc 40 enx))) ". Ending Width is " (rtos (cdr (assoc 41 enx)))". Match Starting or Ending Width or specify a Value [Start/End/Value] ? <" *ans* ">: "))) ( *ans* )))
    						(cond
    							((wcmatch *ans* "S*")
    								(setq pw1 (cdr (assoc 40 enx)))
    							)
    							((wcmatch *ans* "E*")
    								(setq pw1 (cdr (assoc 41 enx)))
    							)
    							((wcmatch *ans* "V*")
    								(initget (+ 1 4))
    								(setq pw1 (getreal "\nSpecify width value: "))
    							)
    						)
    					)
    				)
    				(setq pw1 (cdr (assoc 43 enx)))
    			)
    			(if pw1 
    				(command
    					"_.explode" ent
    					"_.pedit" "_m" "_p" "" "_w" pw1 ""
    				)
    			)
    			(setvar 'peditaccept ped)
    			(setvar 'cmdecho cmd)
    			)
    		)
    	)
    	(if sUndo (vlax-invoke (vla-get-ActiveDocument (vlax-get-acad-object)) 'EndUndoMark))
    	(princ)
    )(vl-load-com)(princ)
    I don't know why when i added the (strcat, the lisp would error out on me no matter where in the code i placed it.

Similar Threads

  1. [LISP] Scaling just the "x" and "y" axis
    By chiimayred in forum AutoLISP, Visual LISP & DCL
    Replies: 31
    Last Post: 16th May 2016, 02:46 pm
  2. HELP to include "AcDbAlignedDimension" code for a "Dimension deleting" LISP
    By vernonlee in forum AutoLISP, Visual LISP & DCL
    Replies: 14
    Last Post: 10th Apr 2015, 04:03 pm
  3. Automatically updating "defined width" attributes for MTEXT?
    By Comatosis in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 1
    Last Post: 8th Dec 2011, 09:59 pm
  4. Polyline global width keeps showing up as 1"
    By ammobake in forum AutoCAD General
    Replies: 5
    Last Post: 4th Jun 2009, 10:52 pm
  5. Finding the "width" of a block (.NET)
    By askrius in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 8th Sep 2008, 10:21 pm

Tags for this Thread

Bookmarks

Posting Permissions

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