gp.triple Posted December 1, 2021 Posted December 1, 2021 hello for update my P&ID i wrote a lisp that check the filename and substitute a block "A" with a block "B", "C" with "D" etc etc it's working fine but i'm not sure that is the best way to do it. here an extract: ;;sostituisco linee con quelle straniere ;; Esempio sostituisco "A" con "CW" (if (and (Setq lin_cw (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_cooling-water.dwg")) ;;definisco blocco da inserire RIPETERE UN SETQ PER OGNI LINEA (Setq lin_pw (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_potable-water.dwg")) (Setq lin_hw (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_hot-water.dwg")) (Setq lin_dw (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_demi-water.dwg")) (Setq lin_chw (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_chilled-water.dwg")) (Setq lin_fw (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_fire-water.dwg")) (Setq lin_ww (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_well-water.dwg")) (Setq lin_c (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_steam-condensate.dwg")) (Setq lin_s (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_steam.dwg")) (Setq lin_hs (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_high-pressure-steam.dwg")) (Setq lin_pa (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_plant-air.dwg")) (Setq lin_ia (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_instrument-air.dwg")) (Setq lin_ba (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_breathing-air.dwg")) (Setq lin_sa (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_atmospheric-air-in-suction.dwg")) (Setq lin_aa (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_atmospheric-air.dwg")) (Setq lin_p (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_process-fluid.dwg")) (Setq lin_n (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_nitrogen.dwg")) (Setq lin_ni(findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_nitrogen-low-purity.dwg")) (Setq lin_ga (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_carbon-dioxide.dwg")) (Setq lin_gi (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_inert-gas.dwg")) (Setq lin_av (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_atmospheric-vent.dwg")) (Setq lin_pv (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_vent-to-blow-down.dwg")) (Setq lin_tv (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_vent-to-tox.dwg")) (Setq lin_sv (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_safety-valve-vent.dwg")) (Setq lin_vv (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_vacuum-vent.dwg")) (Setq lin_ns (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_brine.dwg")) (Setq lin_nh (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_ammonia.dwg")) (Setq lin_ps (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_process-sewer.dwg")) (Setq lin_uu (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_chemical-sewer.dwg")) (Setq lin_ss (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_meteoric-sewer.dwg")) (Setq lin_ff (findfile "C:\\dati\\Lamberti_std\\block_update\\blocks\\lin_foam-fluid.dwg")) ( Vl-some '(lambda (nme) (if (wcmatch (strcase (getvar "DWGNAME")) (strcat nme "*.DWG")) ;;se il file inizia con nme ) ) '("CH" "C1" "C2" "LI" "MN" "ON" "NO" "RJ" "SH" "WT") ;;definisco iniziali nome file ) ) (progn ;;procedura sostituzione (command "_-insert" lin_cw "-50,0" "" "" "" "" "" "" "" "" "") ;;inserisco blocco DEFINITO NEL SETQ (entdel (entlast)) (if (setq ss (ssget "_X" '((2 . "lin_acquatorre")))) ;;blocco da sostituire (repeat (setq n (sslength ss)) (setq edata (entget (ssname ss (setq n (1- n))))) (entmod (subst '(2 . "lin_cooling-water") '(2 . "lin_acquatorre") edata)) ;;Prima blocco nuovo e poi quello da cambiare ) ) (command "_-insert" lin_pw "-50,0" "" "" "" "" "" "" "" "" "") ;; inserisco blocco DEFINITO NEL SETQ (entdel (entlast)) (if (setq ss (ssget "_X" '((2 . "lin_acquapotabile")))) ;blocco da sostituire (repeat (setq n (sslength ss)) (setq edata (entget (ssname ss (setq n (1- n))))) (entmod (subst '(2 . "lin_potable-water") '(2 . "lin_acquapotabile") edata)) ;;Prima blocco nuovo e poi quello da cambiare ) ) (command "_-insert" lin_hw "-50,0" "" "" "" "" "" "" "" "" "") ;; inserisco blocco DEFINITO NEL SETQ (entdel (entlast)) (if (setq ss (ssget "_X" '((2 . "lin_acquacalda")))) ;blocco da sostituire (repeat (setq n (sslength ss)) (setq edata (entget (ssname ss (setq n (1- n))))) (entmod (subst '(2 . "lin_hot-water") '(2 . "lin_acquacalda") edata)) ;;Prima blocco nuovo e poi quello da cambiare ) ) (command "_-insert" lin_dw "-50,0" "" "" "" "" "" "" "" "" "") ;; inserisco blocco DEFINITO NEL SETQ (entdel (entlast)) (if (setq ss (ssget "_X" '((2 . "lin_acquademi")))) ;blocco da sostituire (repeat (setq n (sslength ss)) (setq edata (entget (ssname ss (setq n (1- n))))) (entmod (subst '(2 . "lin_demi-water") '(2 . "lin_acquademi") edata)) ;;Prima blocco nuovo e poi quello da cambiare ) ) (command "_-insert" lin_chw "-50,0" "" "" "" "" "" "" "" "" "") ;; inserisco blocco DEFINITO NEL SETQ (entdel (entlast)) (if (setq ss (ssget "_X" '((2 . "lin_acquagelida")))) ;blocco da sostituire (repeat (setq n (sslength ss)) (setq edata (entget (ssname ss (setq n (1- n))))) (entmod (subst '(2 . "lin_chilled-water") '(2 . "lin_acquagelida") edata)) ;;Prima blocco nuovo e poi quello da cambiare ) ) (command "_-insert" lin_fw "-50,0" "" "" "" "" "" "" "" "" "") ;; inserisco blocco DEFINITO NEL SETQ (entdel (entlast)) (if (setq ss (ssget "_X" '((2 . "lin_acquantincendio")))) ;blocco da sostituire (repeat (setq n (sslength ss)) (setq edata (entget (ssname ss (setq n (1- n))))) (entmod (subst '(2 . "lin_fire-water") '(2 . "lin_acquantincendio") edata)) ;;Prima blocco nuovo e poi quello da cambiare ) ) is possible to write a list of original block and a list of new block an cycle the substitution? thanks Quote
ronjonp Posted December 2, 2021 Posted December 2, 2021 Answered here: http://www.theswamp.org/index.php?topic=57197.msg607269#msg607269 Quote
Recommended Posts
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.