Jump to content

AutoLISP routine not working in German AutCAD


Recommended Posts

Posted (edited)

Hi everybody,

I'm trying to perform a very simple task, but the LISP just won't work on my German AutoCAD (Civil 3D 2025 German).

 

I have a LISP routine to get all COGO points on layers with "-PT" suffix and want them to be turned off and frozen.

 

(defun c:test01 (/ ss)
(vl-load-com)
   (setq ss 
      (ssget "_X" '((-4 . "<AND")(0 . "AECC_COGO_POINT")(8 . "*-PT")(-4 . "AND>")))
   )
   (command "_-layer" "freeze" ss "")
   (command "_-layer" "off" ss "")
   (sslength ss)
   (setq ss nil)
   (princ)
)

 

I get an error upon running the LISP. Something like "invalid option keyword" since the -LAYER option "freeze" is called "frieren" in German.

 

I've tried various command* combinations, but all fail.

*) _-COMMAND or _.-COMMAND

 

I'm lost here, those non-localized prefixes should work and I can't figure out why.

Any help appreciated

Edited by Vittorio
added text
Posted (edited)

You cant freeze\off only the points its either the whole layer or nothing. this makes a selection set and process it to find what layers they are on and turns feezes and turns off those layers. if their are other things on that layer they will also be frozen and off.

 

(defun c:test01 ( / ss lay laylst)
  (vl-load-com)
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (setq layers (vla-get-Layers doc))
  (if (setq ss (ssget "_X" '((0 . "AECC_COGO_POINT") (8 . "*-PT"))))
    (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
      (setq lay (cdr (assoc 8 (entget ent))))
      (if (not (member lay laylst))
        (setq laylst (cons lay laylst))
      )
    )
    (foreach lay laylst
      (setq layerObj (vla-Item layers lay))
      (vla-put-Freeze layerObj :vlax-true)
      (vla-put-Off layerObj :vlax-true)
    )
    (prompt "\nNo matching COGO points found.")
  )
  (princ)
)

 

Edited by mhupp
update to visual lisp
  • Agree 2
Posted (edited)
43 minutes ago, mhupp said:
(Command "_.-Layer" "off" lay "")

I probably you need to add (_) before "off"

(Command "_.-Layer" "_off" lay "") ???

I don't have the "_FREEZE" command in Autocad 2021.
(Unknown "_FREEZE" command). 
But there is a command "_.LAYFRZ".

To test the command, type "_FREEZE" on the command line.

Edited by Nikon
  • Agree 1
Posted (edited)

@Vittorio

 

As @Nikon somewhat related, you should put an "_" (underscore) before all "option" selections within the command as well as the command name itself, to avoid localization problems.

Example:

(command "_.-layer" "_freeze" ss "")

(command "_.-layer" "_off" ss "")

 

Also as @mhupp related, you cannot free and turn off a selection, but only the whole layer.

Edited by pkenewell
Posted

Oh dear, my mistake. I didn't think it through. It's obvious that objects cant be frozen or turned off so I rewrote and shortened my functions to this:

 

; Freeze and turn off layers with -PT suffix
(defun c:zOff ()
   (command-s "_-layer" "_freeze" "*-PT" "")
   (command-s "_-layer" "_off" "*-PT" "")
   (princ)
)
; Thaw and turn on layers with -PT suffix
(defun c:zOn ()  
   (command-s "_-layer" "_thaw" "*-PT" "")
   (command-s "_-layer" "_on" "*-PT" "")
   (princ)
)

 

Now they do exactly what I need them to, but is that foolproof?

I tested the function in a drawing that contains at least one of the above mentioned layers and on a drawing that doesn't. No issues, only a message like "no matching layers found".

That should be fine.

 

I've read that VL(A(X))-functions are faster, but the code code would be bulky.

 

Do you recommend something different from my code?

 

Best regards

 

  • Like 1
Posted (edited)
8 hours ago, Vittorio said:

Oh dear, my mistake. I didn't think it through. It's obvious that objects cant be frozen or turned off so I rewrote and shortened my functions to this:

 

<code>

 

Now they do exactly what I need them to, but is that foolproof?

I tested the function in a drawing that contains at least one of the above mentioned layers and on a drawing that doesn't. No issues, only a message like "no matching layers found".

That should be fine.

 

I've read that VL(A(X))-functions are faster, but the code code would be bulky.

Do you recommend something different from my code?

 

Best regards

 

 

in good programming its harder to know when code will fail or do things you don't want. If your ok with turning off all layers that end in -PT. might have some layer that doesn't have points or something. The command might do this already cant test right now but list out all layers that were turned off as a double check.

 

and while command is slower than vla or entmake and has some other quarks its often times simpler/easier to use. as this for example two lines of code vers what i just posted.

(defun c:foo ( / doc layers lay name laylist)
  (vl-load-com)
  (setq laylist '())
  (vla-StartUndoMark (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))))
  (setq layers (vla-get-Layers doc))
  (vlax-for lay layers
    (if (wcmatch (setq name (strcase (vla-get-Name lay))) "*-PT")
      (progn
        (setq laylist (cons name laylist)) ;build list of layer names
        (vla-put-Freeze lay :vlax-true)
        (vla-put-Off lay :vlax-true)
      )
    )
  )
  (vla-EndUndoMark doc)
  (if laylist
    (progn
      (princ (strcat "\nLayers frozen and turned off (" (itoa (length laylist)) "):\n"))
      (foreach n (reverse laylist)
        (princ (strcat "  " n "\n"))
      )
    )
    (princ "\nNo Layers Matching *-PT found.")
  )
  (princ)
)

 

You could probably combine those two functions into one using ldata as a toggle between on and off. ill post later tonight.

Edited by mhupp
  • Like 3
Posted

This will toggle between states using ldata to remember last state. Defaults to turning off if the command hasn't been run before.

 

;;----------------------------------------------------------------------------;;
; Toggle Freeze state of layers with -PT suffix
; https://www.cadtutor.net/forum/topic/99073-autolisp-routine-not-working-in-german-autcad/
(defun c:foo (/ frz)
  (or (setq frz (vlax-ldata-get "frz" "toggle")) (setq frz "Off"))
  (if (eq frz "Off")
    (progn
      (vlax-ldata-put "frz" "toggle" "On")
      (command-s "_-layer" "_freeze" "*-PT" "")
      (command-s "_-layer" "_off" "*-PT" "")
    )
    (progn
      (vlax-ldata-put "frz" "toggle" "Off")
      (command-s "_-layer" "_thaw" "*-PT" "")
      (command-s "_-layer" "_on" "*-PT" "")
    )
  )
  (princ)
)

 

 

  • Like 1

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...