Jump to content

LISP "Unknown Command" error after running lisp


KraZeyMike

Recommended Posts

mergelayers function isn't properly closed so you have an extra right pren. This is merge layer function i came up with. probably need to change the two command lines to entmod or something. to make it more stable but it does the job as long as things are all on the same tab. like this wouldn't error if you where trying to change the title blocks to a different layer.  but it would only work on the current layout.

 

it uses two list "old layer" and "new layer" passes them to the merge command. But I kinda like how you have yours it less room to get mixed up. I think their is an express tools command to merge layers for autoCAD. But not for BricsCAD that's why I had to make this.

 

(defun c:HPO ()
  (MLayer '("*outdoor*" "*building*" "*setout*,*offset*" "bdy-stage*,bdy-design*,bdy,dp*,cp*,*stage*") '("HPO-Outdoor" "HPO-Building" "HPO-Setout" "Bdy"))
  (princ)
)
;;----------------------------------------------------------------------------;;
;; Merge Layers (MLayer '(oldlayers1, oldlayers2) '(newlayer1, newlayer2))
(defun MLayer (#OldLayers #NewLayers / #Layers)
  (vl-load-com)
  (mapcar
    '(lambda (o n)
             (and (tblsearch "Layer" o) 
                  (or (tblsearch "layer" n) (entmake (list '(0 . "LAYER") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbLayerTableRecord") (cons 2 n) '(70 . 0) '(62 . 3))))
               (progn
                 (setq SS (ssget "X" (list (cons 8 o))))
                 (vl-cmdf "_Chprop" SS "" "LA" n "")
                 (vl-cmdf "_Purge" "LA" o "N")
               )
             ) ;_ and
     ) ;_ lambda
    #OldLayers
    #NewLayers
  ) ;_ mapcar
)

 

Edited by mhupp
Link to comment
Share on other sites

  • 3 weeks later...

Thanks for the reply mhupp.

 

This is my first attempt at combining two functions into the one lisp. I've been  fiddling with the parentheses to try and remove the "Unkown command" flag at the end. But I only seem to get it to then run automatically every time a drawing is opened. Only way I can get it to work is with the defun command is as I've uploaded it.
Good news is the lisp works. I'd just like to perfect it

Edited by KraZeyMike
Link to comment
Share on other sites

If you use Notepad ++ it has a inbuilt Lisp check so can see start and end ( ) very helpful. Notepad++ is free. Also has a run lisp code from Notepad++.

 

  • Like 1
Link to comment
Share on other sites

So what I think is happening

In your final selection set, sel2, you are cleaning up the drawing a bit and then deleting items. If this selection set doesn't exist (ie. it didn't find anything), then the erase is erasing nil I think something to this effect:

(command _erase "" "")

 

 

Nil acting like an enter / space, the second "" is again like another enter / space which is repeat the last command line input "HPO" - and since HPO is a LISP and not a command, HPO is an unknown command.

 

If you do something to fix that it should work, something like this at the end:

 

  (if (= sel2 nil)
    () ; if sel2 is a 'nil' selection, do nothing
    (command "_erase" sel2 "") ; if sel2 is a selection, then erase it
)

 

  • Like 1
Link to comment
Share on other sites

(if
  (or
    (and
      sel2
      (= (type sel2) 'pickfirst)
      (vl-some '(lambda (x) (not (vlax-erased-p x)))
        (setq sel2
          (vl-remove-if 'listp
            (mapcar 'cadr
              (ssnamex sel2)
            )
          )
        )
      )
    )
    (and
      sel2
      (= (type sel2) 'ename)
      (not (vlax-erased-p sel2))
    )
  )
  (foreach ent (if (= (type sel2) 'ename) (list sel2) sel2)
    (if (not (vlax-erased-p ent))
      (entdel ent)
    )
  )
)

 

Or simply :

 

(if sel2
  (cond
    ( (= (type sel2) 'pickfirst)
      (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex sel2)))
        (if (not (vlax-erased-p ent))
          (entdel ent)
        )
      )
    )
    ( (and (= (type sel2) 'ename) (not (vlax-erased-p sel2)))
      (entdel sel2)
    )
  )
)

 

Edited by marko_ribar
Link to comment
Share on other sites

Just tried those and while it still works I get that same flag at the end. ("Unknown Command")
One thing I did notice is that if there are no layers to merge and the command therefore only deletes layers based on the sel2 that flag is gone. 
So I think it may be an issue with my merge function and not the sel2 erase.
At this point the command works fine so I have just been ignoring the flag at the end, but it would be nice to fix it up properly.

Thank you for the suggestions.

Link to comment
Share on other sites

Just checked and the ideas work on my computer and CAD which is odd.

 

 

 

(defun c:HPO (/ lst)

  (setq	lst '(("*outdoor*" "HPO-Outdoor")
	      ("*building*" "HPO-Building")
	      ("*setout*,*offset*" "HPO-Setout")
	      ("bdy-stage*,bdy-design*,bdy,dp*,cp*,*stage*" "Bdy")
	     )
  )

  (foreach e lst (mergelayers (car e) (cadr e)))
  (princ)
)
(defun mergelayers (match to / lst def lay)
  (setq str "")
  (or (tblsearch "LAYER" to)
      (command "_.LAYER" "_N" to "")
  )
  (while (setq def (tblnext "LAYER" (null lay)))
    (if	(and (wcmatch (strcase (setq lay (cdr (assoc 2 def))))
		      (strcase match)
	     )
	     (not (wcmatch (strcase lay)
			   (strcat "*|*,0,DEFPOINTS," (strcase to))
		  )
	     )
	)
      (setq lst (cons lay lst))
    )
  )
  (if lst
    (progn
      (command "_.LAYMRG")
      (foreach e lst (command "_Name" e))
      (command "" "_N" to "_Y")
    )
  )
  (setq	sel2 (ssget "_X"
		    '((-4 . "<or")
		      (8 . "*-HPO*")
		      (8 . "*Survey*")
		      (8 . "*Wall*")
		      (8 . "*U-*")
		      (8 . "*SCIMS*")
		      (8 . "Bdy-Tie")
		      (8 . "*Traverse*")
		      (8 . "*Fence*")
		      (8 . "*Road*")
		      (8 . "*Check*")
		      (8 . "*Chk*")
		      (-4 . "or>")
		     )
	     )
  )
  (sssetfirst nil sel2)
  (if (= sel2 nil)
    () ; if sel2 is a 'nil' selection, do nothing
    (command "_erase" sel2 "") ; if sel2 is a selection, then erase it
  )
)

 

 

  • Like 1
Link to comment
Share on other sites

  • 8 months later...

Thanks so much Steven,  Sorry for the late reply. This worked perfectly. Much appreciated. 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...