Author Topic: Need to lurn..  (Read 5794 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
Need to lurn..
« on: November 23, 2005, 10:08:32 PM »
Hi all..

I have created this simple routine...

Code: [Select]
;| ;;
Replace word in a layer ;;
By: Andrea Andreetti |;

(defun c:MCR (/ layer_list lfound ltell ls1 lr)
(setq layer_list (ai_table "layer" 4))
(setq lfound (getstring "Mot du calque à changer : ")
      ltell (getstring "Par le mot : "))
(foreach n layer_list
  (setq ls1 (vl-string-search lfound n))
  (if ls1
    (progn
    (setq lr (vl-string-subst ltell lfound n))
    (vl-cmdf "_.-rename" "_LA" n lr)
    )
  )
)
)  

But can anyone show me some other way to do similar with VLX or any other mode ?
Just curious to lurn.. :police:
Keep smile...

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Need to lurn..
« Reply #1 on: November 23, 2005, 11:42:01 PM »
This will need some work on your part.

Do you know how to determine the Layers Collection.
Do you know how to iterate the collection.
Do you know how to determine the Name and/or Value of an object.


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Need to lurn..
« Reply #2 on: November 24, 2005, 02:39:40 AM »
.. but if you want to learn that shouldn't be an issue .. :-)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Adesu

  • Guest
Re: Need to lurn..
« Reply #3 on: November 24, 2005, 03:14:00 AM »
Hi Andrea,how about this
Code: [Select]
;| ;;
Replace word in a layer ;;
By: Andrea Andreetti |;

(defun c:MCR (/ layer_list lfound ltell ls1 lr)
  ;(setq layer_list (ai_table "layer" 4))
  (setq layer_list (table "layer"))
  (setq lfound (getstring "Mot du calque à changer : "))
  (setq ltell (getstring "Par le mot : "))
  (foreach n layer_list
    (setq ls1 (vl-string-search lfound n))
    (if ls1
      (progn
(setq lr (vl-string-subst ltell lfound n))
(vl-cmdf "_.-rename" "_LA" n lr)
)
      )
    )
  ) 

(defun table (s / d r)
  (while (setq d (tblnext s (null d)))
    (setq r (cons (cdr (assoc 2 d)) r))
  )
)



Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: Need to lurn..
« Reply #4 on: November 24, 2005, 04:15:48 AM »
In ActiveX:
Code: [Select]
(defun c:MCR (/ lfound ltell AcaDoc LayCol LayNme LayObj NewNme)
 (setq lfound (getstring "\nMot du calque à changer : ")
       ltell  (getstring "Par le mot : ")
       AcaDoc (vla-get-ActiveDocument (vlax-get-acad-object))
       LayCol (vla-get-Layers AcaDoc)
 )
 (vlax-for Obj LayCol
  (setq LayNme (vla-get-Name Obj))
  (if (and
       (not (vl-position (strcase LayNme) '("0" "DEFPOINTS")))
       (vl-string-search lfound LayNme)
      )
;;; Note that the search is case-sensitive, and that vl-string-subst
;;; substitutes only the first occurrence it finds of the string.
   (setq NewNme (vl-string-subst ltell lfound LayNme)
         LayObj Obj
   )
  )
 )
 (cond
  ((not NewNme)
   (princ "Calque à changer n'existe pas.")
  )
  ((not
    (vl-catch-all-error-p
     (vl-catch-all-apply '(lambda () (vla-Item LayCol NewNme)))
    )
   )
   (princ "Le nouveaux nom du calque déjà existe.")
  )
  (T
   (vla-put-Name LayObj NewNme)
  )
 )
 (princ)
)
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Need to lurn..
« Reply #5 on: November 24, 2005, 04:23:07 AM »
Andrea wanted to test against bit 4 too Jürg.

Quote
;;; (ai_table <table name> <bit> )
;;;
;;; Returns a list of items in the specified table.  The bit values have the
;;; following meaning:
;;;  0  List all items in the specified table.
;;;  1  Do not list Layer 0 and Linetype CONTINUOUS.
;;;  2  Do not list anonymous blocks or anonymous groups.
;;;         A check against the 70 flag for the following bit:
;;;                  1  anonymous block/group
;;;  4  Do not list externally dependant items.
;;;         A check against the 70 flag is made for any of the following
;;;         bits, which add up to 48:
;;;                 16  externally dependant
;;;                 32  resolved external or dependant
;;;  8  Do not list Xrefs.
;;;         A check against the 70 flag for the following bit:
;;;                  4  external reference
;;;  16 Add BYBLOCK and BYLAYER items to list.
;;;
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: Need to lurn..
« Reply #6 on: November 24, 2005, 07:17:10 AM »
Andrea wanted to test against bit 4 too Jürg.
AFAIK, there is no property in ActiveX to check for that...
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Need to lurn..
« Reply #7 on: November 24, 2005, 08:28:11 AM »
hmmm... :? interesting...

But I have found a little problem with this...
in fact if I have a layer named like    M-ALUMINUM-TEXT and need to change M- by E-

This will replace only the first string found in the layer name
like  E-ALUMINUM-TEXT  and not E-ALUMIUE-TEXT

see ?
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Need to lurn..
« Reply #8 on: November 24, 2005, 08:59:34 AM »
also..

why this is not working ??


Code: [Select]
(defun c:MCR ()(/ layer_list lfound ltell ls1 lr)
(setq layer_list (ai_table "layer" 0))
(setq lfound (strcase (getstring "Mot du calque à changer : "))
      ltell (getstring "Par le mot : "))
(foreach n layer_list
  (setq ls1 (vl-string-search lfound (strcase n)))
  (if ls1
    (progn
    (setq lr (vl-string-subst ltell lfound n))
    (vl-cmdf "_.-rename" "_LA" n lr)
    )
  )
)
)
Keep smile...

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Need to lurn..
« Reply #9 on: November 24, 2005, 09:19:19 AM »
What have you done to debug it ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: Need to lurn..
« Reply #10 on: November 24, 2005, 09:58:58 AM »
why this is not working ??
See comment in my code... For a function that replaces all occurrences of a pattern visit my homepage -> Free Stuff and search for 'VxStringSubst'
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Need to lurn..
« Reply #11 on: November 24, 2005, 11:17:51 AM »
What have you done to debug it ?

this....

Code: [Select]
(defun c:MCR ();;(/ repxok layer_list lfound ltell ls1 lr)
(setvar "CMDECHO" 0) 
  (check_repx)
(if repxok
  (progn
(setq layer_list (ai_table "layer" 0))
(setq lfound (strcase (getstring "Mot du calque à changer : "))
      ltell (getstring "Par le mot : "))
(foreach n layer_list
(setq TL (strcase n))
(alert (strcat TL "     " lfound))
  (setq ls1 (vl-string-search lfound TL))
  (if ls1
    (progn
    (setq lr (vl-string-subst ltell lfound n))
    (vl-cmdf "_.-rename" "_LA" n lr)
    )
  )
)
))
  (prompt "Calques mis à jour")(princ)
  )
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Need to lurn..
« Reply #12 on: November 24, 2005, 11:19:11 AM »
why this is not working ??
See comment in my code... For a function that replaces all occurrences of a pattern visit my homepage -> Free Stuff and search for 'VxStringSubst'

And your website is...!?? :?
Keep smile...

LE

  • Guest
Re: Need to lurn..
« Reply #13 on: November 24, 2005, 11:27:45 AM »
Click in the WWW url link

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Need to lurn..
« Reply #14 on: November 24, 2005, 11:28:33 AM »
Or look at his sig.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Need to lurn..
« Reply #15 on: November 24, 2005, 05:36:14 PM »
Oops, sorry..to much work i think.. :-D

by the way...

I have an error when trying to rename a layer who already exist..
I think I need to remake my routine... :-P
Keep smile...

Royalchill

  • Guest
Re: Need to lurn..
« Reply #16 on: November 29, 2005, 01:32:05 PM »
I found this old lisp. I did not write it but it works perfect. Hope it is some help

;At the command line, type (load "c:/lispdir/RENLYR")
;where c:/ is the drive where RENLYR.lsp is contained
;where lispdir/ is the directory where RENLYR.lsp is contained

(Defun C:RENLYR (/ e e-inf e-lyr txtlist sstxt sse see-inf sse-txt)
  (prompt "\n")
  (princ)
  (while (= (setq e (car (entsel "\rSelect entity of layer to rename: "))) nil))
  (setq
    e-inf (entget e)
    e-lyr (cdr (assoc 8 e-inf))
  )
  (if (/= e-lyr "0")
    (progn
      (setq txtlist (list (cons 0 "TEXT") (cons 1 e-lyr) (cons 10 (getvar "viewctr")) (cons 40 0.000001) (cons 50 0.0)))
      (entmake txtlist)
      (setq sstxt (entlast))
      (command "ddedit" sstxt "")
      (setq
        sse (entlast)
        sse-inf (entget sse)
        sse-txt (cdr (assoc 1 sse-inf))
      )
      (if (and (/= (strcase sse-txt) (strcase e-lyr)) (/= sse-txt "") (= (wcmatch sse-txt "* *") nil))
        (command "rename" "layer" e-lyr sse-txt)
        (cond
          ((= (strcase sse-txt) (strcase e-lyr))
              (prompt "\nLayer name has not been modified, name is identical")
              (princ)
           )
          ((= sse-txt "")
              (prompt "\nLayer name has not been modified, nil length string")
              (princ)
           )
          ((/= (wcmatch sse-txt "* *") nil)
              (prompt "\nLayer name has not been modified, name has space")
              (princ)
           )
         )
      )
      (command "erase" sstxt "")
    )
    (progn
      (if (= e-lyr "0")
        (progn
          (prompt "\nCannot rename layer 0")
          (princ)
        )
      )
    )
  )
  (princ)
)