Jump to content

Recommended Posts

Posted

Hello everyone,

I’ve inherited an AutoLisp file from my predecessor. So far, the file works, though I can’t really judge if it has been optimally written. However, it saves both my colleagues and me a lot of time, and I can adjust most parts of it to my needs.

That said, I’m running into issues with a specific section of the code:

 

;======================================== W A S S E R  L A Y E R ========================================
;*******************TEST Start
(command "_-layer" "N" "Bezugslinie-Text" "")
;*******************TEST End

;========================================  L A Y E R  Z U W E I S U N G ========================================
;*******************TEST Start
;BT - Bezugslinie Text
(setq BT (ssget "X" '(
(0 . "MTEXT")
(6 . "Continuous")
(370 . 180)
)))
(command "_CHANGE" BT "" "EI" "LA" "Bezugslinie-Text" "F" "VonLayer" "LTY" "VonLayer" "LS" "VonLayer" "")
;*******************TEST End

 

The goal is to select MTEXT objects with a line thickness of 0.18 mm and assign them to the appropriate layer. Using the Quick Select tool works fine for this, but the LISP code doesn't seem to behave as expected.

Before I share the full LISP file, I wanted to check if my approach makes sense. Is the issue with my plan clear, or have I provided too few details?

Thanks in advance for any help!

 

 

The Full code:
 

(defun c:sweWASSER ()
;***** TO-DO*****
;Wasser Bezugslinie der Beschriftung aus Auswahl ausschließen über Linienstärke möglich?


;======================================== V A R I A B L E N ========================================
 
(setq oldsnap (getvar "osmode"))
;save snap settings
 
(setq oldblipmode (getvar "blipmode"))
;save blipmode setting

;Switch OFF System Variables
 
(setvar "osmode" 0)
;Switch OFF snap
 
(setvar "blipmode" 0)
;Switch OFF Blipmode


;======================================== A U S W A H L ========================================


(setq wasser1 (ssget "X" '((-4 . "<OR")
(8 . "Ebene 290")
(8 . "W_Anlage")
(8 . "W_Anlage_Beschriftung")
(8 . "W_Armatur")
(8 . "W_Armatur_Beschriftung")
(8 . "W_freie_Linie")
(8 . "W_freier_Text_Beschriftung")
(8 . "W_freies_Symbol")
(8 . "W_HA_Abgang")
(8 . "W_HA_Leitungsabschnitt_Beschriftung")
(8 . "W_HA_Anschluss")
(8 . "W_HA_Knoten")
(8 . "W_HA_Schieber")
(8 . "W_HA_Zähler")
(8 . "W_Hydrant")
(8 . "W_KKS_Isoliertrennstelle_Messkontakt")
(8 . "W_Knoten")
(8 . "W_Konstruktionspunkt")
(8 . "W_Lagepunkt")
(8 . "W_Messwagen")
(8 . "W_Messzone")
(8 . "W_Rohrkreuzung")
(8 . "W_Schemazeichnung")
(8 . "W_Schieber")
(8 . "W_Schieber_Beschriftung")
(8 . "W_Zähler")
(8 . "Wasser-Detail")
(8 . "Wasser-Rest")
(8 . "W_HA_Zähler_Beschriftung")
(-4 . "OR>"))))


;======================================== F U N K T I O N S A B L Ä U F E ========================================


(command "-xref" "l" "*"
	)         ;End Command

(command "_-PURGE" "_all" "*" "_n"
	)         ;End Command

(command "ZOOM" "GRENZEN"
	)         ;End Command

(command "_ERASE" wasser1 ""
	)         ;End Command 

(command "_-PURGE" "_all" "*" "_n"
	)         ;End Command

(command "REGENALL"
	)         ;End Command


;======================================== W A S S E R  L A Y E R ========================================
;*******************TEST Anfang
(command "_-layer" "N" "Bezugslinie-Text" "")
;*******************TEST ENDE

(command "_-layer" "N" "SWE_V_Wasser_VW_SWE" "")

(command "_-layer" "N" "SWE_V_Wasser_Text_SWE" "")

(command "_-layer" "N" "SWE_V_Wasser_HW_SWE" "")

(command "_-layer" "N" "SWE_V_Wasser_AW_SWE" "")

(command "_-layer" "N" "SWE_V_Wasser_stillgelegt_SWE" "")

(command "_-layer" "N" "SWE_V_Wasser_HA_SWE" "")

(command "_-layer" "N" "SWE_V_Wasser_Schutzrohr_SWE" "")

(command "_-layer" "N" "SWE_V_Wasser_Bemaßung_SWE" "")

(command "_-layer" "SE" "0" "")

(command "REGENALL")


;========================================  L A Y E R  Z U W E I S U N G ========================================
;*******************TEST Anfang
;BT - Bezugslinie Text
(setq BT (ssget "X" '(
(0 . "MTEXT")
(6 . "Continuous")
(370 . 180)

)))
(command "_CHANGE" BT "" "EI" "LA" "Bezugslinie-Text" "F" "VonLayer" "LTY" "VonLayer" "LS" "VonLayer" "")
;*******************TEST ENDE

;VW - Versorgungsleitung
(setq VW (ssget "X" '(
(6 . "Continuous")
(8 . "W_VL_HL_Leitungsabschnitt")

)))
(command "_CHANGE" VW "" "EI" "LA" "SWE_V_Wasser_VW_SWE" "F" "VonLayer" "LTY" "VonLayer" "LS" "VonLayer" "")


;WaB - Wasserleitung außer Betrieb
(setq WaB (ssget "X" '(
(6 . "30")
(8 . "Wasser-Stillgelegt")
)))
(command "_CHANGE" WaB "" "EI" "LA" "SWE_V_Wasser_stillgelegt_SWE" "F" "253" "LTY" "VonLayer" "LS" "VonLayer" "")


;WaBT - Wasser außer Betrieb Text
(setq WaBT (ssget "X" '(
(0 . "MText")
(8 . "Wasser-Stillgelegt")
)))
(command "_CHANGE" WaBT "" "EI" "LA" "SWE_V_Wasser_stillgelegt_SWE" "F" "253" "LTY" "VonLayer" "LS" "VonLayer" "")


;Beschriftung
(setq BES (ssget "X" '(
(8 . "W_VL_HL_Leitungsabschnitt_Beschriftung")
)))
(command "_CHANGE" BES "" "EI" "LA" "SWE_V_Wasser_Text_SWE" "F" "VonLayer" "LTY" "VonLayer" "LS" "VonLayer" "")


;Schutzrohre und Bemaßung sprengen
(setq SBS (ssget "X" '((-4 . "<OR")(8 . "W_Schutzrohr")(8 . "Wasser-Bemassung")(-4 . "OR>")
)))
(setq a (getvar "qaflags"))
(setq b (setvar "qaflags" 1))
(command "_EXPLODE" SBS "")
(setvar "qaflags" a)

;Schutzrohr
(setq SR (ssget "X" '((-4 . "<OR")(8 . "W_Schutzrohr")(8 . "W_Schutzrohr_Beschriftung")(-4 . "OR>")
)))
(command "_CHANGE" SR "" "EI" "LA" "SWE_V_Wasser_Schutzrohr_SWE" "F" "VonLayer" "LS" "VonLayer" "")

;Bemaßung
(setq BEM (ssget "X" '(
(-4 . "<OR")(8 . "W_freier_Text")(8 . "Wasser-Bemassung")(-4 . "OR>")
)))
(command "_CHANGE" BEM "" "EI" "LA" "SWE_V_Wasser_Bemaßung_SWE" "F" "253" "")

;Hausanschlüsse
(setq HA (ssget "X" '(
(8 . "W_HA_Leitungsabschnitt")
)))
(command "_CHANGE" HA "" "EI" "LA" "SWE_V_Wasser_AW_SWE" "F" "VonLayer" "LTY" "VonLayer" "LS" "VonLayer" "")


	;Auswahl
(setq wasser2 (ssget "X" '((-4 . "<OR")(8 . "Wasser-Stillgelegt")(-4 . "OR>"))))
(command "_ERASE" wasser2 ""
	)         ;End Command 

(command "_-PURGE" "_all" "*" "_n"
	)         ;End Command

;Modell Regenerieren
(command "REGENALL")


;======================================== T E X T S T I L  C H A N G E ========================================


  ;; Alle Texte und MText in der Zeichnung auswählen
  (setq ss (ssget "X" '((0 . "TEXT,MText"))))

  ;; Wenn Texte vorhanden sind, den Stil ändern
  (if ss
    (progn
      (setq i 0)
      (while (< i (sslength ss))
        (setq e (entget (ssname ss i)))  ; Entität der Auswahl bekommen
        (setq eneu (subst (cons 7 "STANDARD") (assoc 7 e) e))  ; Stil auf "STANDARD" ändern
        (entmod eneu)  ; Entität mit dem neuen Stil aktualisieren
        (setq i (1+ i))
      )
      (princ "\nAlle Texte auf den Stil 'STANDARD' gesetzt.")
    )
    (princ "\nKeine Texte in der Zeichnung gefunden.")
  )


;======================================== R E S E T   V A R I A B L E ========================================


(setvar "osmode" oldsnap)
;Reset snap
 
(setvar "blipmode" oldblipmode)
;Reset blipmode

(princ)
;finish cleanly
 
)	;Ende defun



(princ)	;load cleanly

 

Posted

Hi @cadler,

 

Try this (you will se inside the code "comment:", also, there is a plenty way to do changing layers of entities):

 

;======================================== W A S S E R  L A Y E R ========================================
;;OLD START
;*******************TEST Start
(command "_-layer" "N" "Bezugslinie-Text" "")
;*******************TEST End
;;OLD END

;;NEW PART OF CODE START
(setq def_name "Bezugslinie Text") ;; you can here change the layer name in whatever you want
(if (not (tblsearch "LAYER" def_name))
    (progn
      (command "-layer" "n" def_name "")
      )
    )
;;comment: This part of code will search if layer "Bezugslinie Text" already exist in the drawing, if not, it will make that layer.
;;NEW PART OF CODE END


;========================================  L A Y E R  Z U W E I S U N G ========================================
;*******************TEST Start
;BT - Bezugslinie Text
(setq BT (ssget "X" '((0 . "MTEXT") (6 . "Continuous") (370 . 180))))

;;OLD START
(command "_CHANGE" BT "" "EI" "LA" "Bezugslinie-Text" "F" "VonLayer" "LTY" "VonLayer" "LS" "VonLayer" "")
;*******************TEST End
;;OLD END

;;NEW PART OF CODE START
(setq len (sslength BT) ;; this is the length of selection set from variable "BT" (for e.g. 50 entities which are "MTEXT")
      i 0)
(while (< i len)
  (setq old_lay (cdr (assoc 8 (entget (ssname BT i))))) ;; old layer in which are "MTEXT" is
  (entmod (subst (cons 8 def_name) (cons 8 old_lay) (entget (ssname BT i))))
  (setq i (1+ i))
  )
;;comment: inside while loop, foreach entity "MTEXT" from selection set "BT", it will change the old layer into to "Bezugslinie-Text" which are stored in variable "def_name" using "entmod".
;;NEW PART OF CODE END

 

Hope it will be helpful.

 

Best regards.

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