CADsite forum

AutoCAD => Autolisp => Topic gestart door: pe op do 31 05 2012, 11:24:39

Titel: hernoemen van een gedeelte van lagen
Bericht door: pe op do 31 05 2012, 11:24:39
Hallo,

ik heb de volgende vraag. Ik wil een aantal laagnamen die beginnen met AL veranderen in FL of TL. Dus:

AL7.......... --> FL7..........
AL7.......... --> FL8..........
AL9.......... --> TL9..........

En zo hebben we nog meerdere lagen waarvan de eerste 2 letters/eerste cijfer gewijzigd moeten worden. Ik heb een script gevonden waarmee ik lagen kan hernoemen. Het nadeel van deze is dat in deze script je de exacte laagnaam moet neerzetten. Ik zoek er een die alleen kijkt naar de 1e 2 letters en cijfer en die hernoemt en de rest van de laagnaam intact laat. De script die ik heb en werkt is:

(defun C:OldLay2NewLay2   (/ OldNewLayLst i OldLay NewLay)
  (setq   OldNewLayLst
    '(
      ("AL72---- vaste gebruikersvoorzieningen" "FL72---- vaste gebruikersvoorzieningen")
      ("AL82---- inrichting los" "FL82---- inrichting los")
      ("AL90---- terrein" "TL90---- terrein")
     )
  )
  (setq i 0)
  (repeat (length OldNewLayLst)
    (setq OldLay (car (nth i OldNewLayLst))
     NewLay (cadr (nth i OldNewLayLst))
    )
    (if   (and (tblsearch "LAYER" OldLay)
        (not (tblsearch "LAYER" NewLay))
   )
      (command "_.RENAME" "_LA" OldLay NewLay)
    )
    (setq i (1+ i))
  )
  (princ)
);;End OldLay2NewLay2

Weet iemand misschien een oplossing?
Titel: Re: hernoemen van een gedeelte van lagen
Bericht door: AdenRob op do 31 05 2012, 16:23:29
Beste pe,

Dit is op te lossen met het commando "rename".

1. Ga naar; format -->rename (rename; commando)
2. Ga bij Named objects naar Layers
3. Type onderin (bij "Old name") AL* (hierbij worden alle lagen geselecteerd welke beginnen met AL)
4. Type onderin (bij "Rename to") FL*
5. Klik op "OK"

Voila.

Met vriendelijke groet,
AdenRob
Titel: Re: hernoemen van een gedeelte van lagen
Bericht door: HofCAD op do 31 05 2012, 16:38:06
Beste Pe,

Of in Lisp met bijvoorbeeld:
(defun C:ChLayPre (/ Doc OldPrefix sLen NewPrefix LayName NewLayName)
   (vl-load-com)
   (setq Doc (vla-get-activedocument (vlax-get-acad-object)))
   (setq OldPrefix (getstring T "Old Layer Prefix: "))
   (setq SLen (strlen OldPrefix))
   (setq NewPrefix (getstring T "New Layer Prefix: "))
   (vlax-for i (vla-get-layers Doc)
      (progn
(setq LayName (vla-get-Name i))
(if (and (= (strcase (substr LayName 1 SLen)) (strcase OldPrefix))
                         (/= LayName "0")
                 )
    (progn
       (setq NewLayName (strcat NewPreFix (substr LayName (1+ SLen))))
       (if (not (tblsearch "LAYER" NewLayName))
  (command "_.-RENAME"
   "_LA"
   LayName
   NewLayName
  )
  (princ (strcat "\nWarning: Impossible to change "
LayName
" in "
NewLayName
)
  )
       )
    )
)
      )
   )
   (princ)
)
(princ "\nChLayPre.lsp loaded. Type CHLAYPRE to run.")
(princ)


Met vriendelijke groet, HofCAD CSI.

PS: Het bijgevoegde programma is iets anders:
     1) Omdat daar de prompt onderdrukt word.
     2) Omdat er ook een commando is voor Blocks.
Titel: Re: hernoemen van een gedeelte van lagen
Bericht door: Rudy op ma 04 06 2012, 08:25:40
Kreeg deze morgen nog een manier om te hernoemen binnen van Mike Williams

Here's a little tip that came to mind when responding to one of our subscriber's problems.  Amy was having problems fixing several attribute values, tags and prompts over multiple blocks.  In her case, there were some misspelled words and incorrect values that were consistent from one block to the next.  It reminded me of a way to use a command in ways most people have never thought of.
Here's a hypothetical scenario.  Let's say you have the prefix "xyzcorp-" at the beginning of 50 different block names, 75 different attribute tags and 100 different layer names.  Then you find out that you need to change all references to "abccorp-".  You could change the block names using the "REN" command (one at a time), the attributes using the "-ATTEDIT" command and the layers using Layer Manager.  And you could spend all day doing that.
Or you could use a little know secret....The DXF command.  Many people only use this command when transferring drawings back and forth between programs other than AutoCAD.  But the awesome thing about the DXF command is that it creates a text file out of your drawing. 
Open your drawing and give the "SAVEAS" command.  When prompted for the name, change the file type to *.DXF and save the file to a known location.  Open Microsoft WordPad and change the document type to "All Documents (*.*) and open the DXF file you created.  Simply do a "find and replace" (Ctrl+H) and enter "xyxcorp-"  in the "find" field and  "abccorp-" in the "replace" field.  All occurrences, regardless of entity type, will be changed.  Save the file and open it in AutoCAD and save back to DWG.

Kan misschien helpen in bepaalde gevallen?
Titel: Re: hernoemen van een gedeelte van lagen
Bericht door: HofCAD op ma 04 06 2012, 09:56:39
Beste Rudy,

Een bijzondere maar ook gevaarlijke oplossing.
Stel bijv. men wil 'PO'  in  'BAD' veranderen,
dan wordt dus POLYLINE ook BADLYLINE.
Verder is er ook geen controle of het wel mogelijk is.
Stel men heeft een laag HL-25 en een laag LN-25,
dan mag men niet 'HL' in 'LN' veranderen.

Met vriendelijke groet, HofCAD CSI.
Titel: Re: hernoemen van een gedeelte van lagen
Bericht door: Rudy op ma 04 06 2012, 13:42:46
Citaat van: HofCAD op ma 04 06 2012, 09:56:39

Een bijzondere maar ook gevaarlijke oplossing.


Volledig akkoord HofCAD, Ik reik hier dan ook maar een tip aan die vekregen heb van Mike.

Mvg,

Rudy