Author Topic: Find and Replace layer attributes  (Read 3807 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Find and Replace layer attributes
« on: January 16, 2008, 12:03:57 PM »
What I'm thinking about is a type of find and replace for layer names or even linetypes, colors etc., only do it from a simple text file some how. For example. You export your current layer configuration to a text file. Pop it open in your favorite text editor and make your changes. Then bring it back into acad. The program reads the edited version and makes the appropriate changes. Or would this be easier to accomplish within the program itself? The only problem I see is lack of regex support from within autolisp.

Thoughts?
TheSwamp.org  (serving the CAD community since 2003)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Find and Replace layer attributes
« Reply #1 on: January 16, 2008, 12:16:11 PM »
I have one that works with ObjectDBX already.  I think it is posted here.  Be right back.

Edit: Found it.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

daron

  • Guest
Re: Find and Replace layer attributes
« Reply #2 on: January 16, 2008, 02:12:15 PM »
I tend to wonder if there would be a way to emulate regex through lisp in order to gain that support? That might be a good challenge.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Find and Replace layer attributes
« Reply #3 on: January 16, 2008, 02:26:07 PM »
I have one that works with ObjectDBX already.  I think it is posted here.  Be right back.

Edit: Found it.

Thanks Tim, I'll give it a look-see.
TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Find and Replace layer attributes
« Reply #4 on: January 16, 2008, 02:37:11 PM »
I tend to wonder if there would be a way to emulate regex through lisp in order to gain that support? That might be a good challenge.

Why emulate regex? Took less than 10 minutes to translate (admittedly quick and dirty, but still) ...

Code: [Select]
(defun c:RegExExample ( / objRegEx strSearchString colMatches )

[color=green]    ;;  see http://www.microsoft.com/technet/scriptcenter/
    ;;           resources/qanda/sept06/hey0920.mspx
    ;;
    ;;  Set objRegEx = CreateObject("VBScript.RegExp")
    ;; 
    ;;  objRegEx.Global = True   
    ;;  objRegEx.Pattern = "[^A-Z0-9]"
    ;; 
    ;;  strSearchString = "Ken Myer"
    ;; 
    ;;  Set colMatches = objRegEx.Execute(strSearchString) 
    ;; 
    ;;  If colMatches.Count > 0 Then
    ;;      Wscript.Echo "The following characters are not allowed:"
    ;;      For Each strMatch in colMatches   
    ;;          Wscript.Echo  strMatch.Value
    ;;      Next
    ;;  End If[/color]

    (setq objRegEx (vlax-create-object "VBScript.RegExp"))
   
    (vlax-put objRegEx 'Global -1)
    (vlax-put objRegEx 'Pattern "[^A-Z0-9]")
   
    (setq
        strSearchString "Ken Myer"
        colMatches      (vlax-invoke objRegEx 'Execute strSearchString)
    )
   
    (if (< 0 (vlax-get colMatches 'Count))
   
        (progn
   
            (princ "The following characters are not allowed:\n")
   
            (vlax-for strMatch colMatches   
                (print (vlax-get strMatch 'Value))
            )
        )
    )
   
    (vlax-release-object colMatches)
    (vlax-release-object objRegEx)

    (princ)   

)

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Find and Replace layer attributes
« Reply #5 on: January 16, 2008, 02:43:31 PM »
I can look around my stuff too if you need Mark.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

daron

  • Guest
Re: Find and Replace layer attributes
« Reply #6 on: January 16, 2008, 04:10:56 PM »
Nice MP.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Find and Replace layer attributes
« Reply #7 on: January 16, 2008, 04:28:46 PM »
Can't you just do it in LISP or did I miss something, again. :-)

Code: [Select]
;;  returns t if str has a bad character
(defun badchar (str)
  (vl-some '(lambda (x) (not (or (< 47 x 58) (< 64 x 91))))
           (vl-string->list str))
)


Code: [Select]
;;  returns a list of bad characters
(defun badchar (str / bad)
  (mapcar '(lambda (x)
     (if (not (or (< 47 x 58) (< 64 x 91)))
                (setq bad (cons x bad))))
    (vl-string->list str))
  (mapcar 'chr bad)
)


Code: [Select]
(defun c:test (/ Rejects)
  (if (setq Rejects (badchar "ABCDzXYZ,019"))
    (mapcar '(lambda(x)(print x)) Rejects)
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Find and Replace layer attributes
« Reply #8 on: January 16, 2008, 04:51:35 PM »
Can't you just do it in LISP or did I miss something, again. :-)

Don't think so! :-)

Example: ( using regex )
Code: [Select]
cat layers ( FROM THIS )
C-ValveWater_ep
C-MeterWater_ep
C-BoxWater_ep
C-AnnoWater_ep

sed -R "s/^(C)-(.*)(Water)(_ep)/\1U-\3-\2-UNDR/" layers ( TO THIS )
CU-Water-Valve-UNDR
CU-Water-Meter-UNDR
CU-Water-Box-UNDR
CU-Water-Anno-UNDR
TheSwamp.org  (serving the CAD community since 2003)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Find and Replace layer attributes
« Reply #9 on: January 16, 2008, 05:30:03 PM »
Never mind :oops:
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.