Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Removing layer prefix created by binding xref

14 REPLIES 14
Reply
Message 1 of 15
joshua_sieglaff
4244 Views, 14 Replies

Removing layer prefix created by binding xref

I am creating a cleaning tool to get rid of un-needed information in a drawing. The Drawings I get have the xref's bound and the prefix "filename$#$" is in front of the layer name. Is there a lisp routine out there that will go through the layers and get rid of that prefix.

Thank you

Joshua
14 REPLIES 14
Message 2 of 15
Anonymous
in reply to: joshua_sieglaff


Hi joshua, try
this:

 

;;;=====================================
(defun
rename_bound_layers ( / layer_name position)

 

  (vl-load-com)

 

  (defun find_pattern_position (string /
position)
    (setq position 1)
    (repeat
(strlen string)
     
(if
       
(and
          (= (substr string
position 1) "$")
         
(numberp
           
(atoi (substr string (1+ position)
1))
         
)
          (= (substr string (+
position 2) 1) "$")
       
)
        (+ position
2)
        (setq position (1+
position))
      )
    )
 
)

 

  (vlax-for layer
   
(vla-get-layers
     
(vla-get-activedocument
       
(vlax-get-acad-object)
      )
   
)
    (setq layer_name (vla-get-name
layer))
    (if (wcmatch layer_name
"*$#$*")
     
(vla-put-name
       
layer
       
(vl-string-left-trim
         
(substr
           
layer_name
           
1
           
(find_pattern_position
layer_name)
         
)
         
layer_name
       
)
      )
    )
 
)
  (princ)
)
;;;=====================================
(defun
C:RBL
()(rename_bound_layers))(princ)
;;;=====================================

 



style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">I
am creating a cleaning tool to get rid of un-needed information in a drawing.
The Drawings I get have the xref's bound and the prefix "filename$#$" is in
front of the layer name. Is there a lisp routine out there that will go
through the layers and get rid of that prefix. Thank you
Joshua
Message 3 of 15

I used your lisp routine but nothing happened. Is there something missing or something that I am not doing correctly?
Message 4 of 15
Anonymous
in reply to: joshua_sieglaff


I don't know, I was testing it here and iti works.
Can you post a little drawing with a dozen or something layers, just for
testing purposes ?


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I
used your lisp routine but nothing happened. Is there something missing or
something that I am not doing correctly?
Message 5 of 15

I must be inept because I can't upload a drawing.
Message 6 of 15
Anonymous
in reply to: joshua_sieglaff


Maybe is just because the problems Autodesk has
with the news server lately, because otherwise is easy like sunday mornings. Use
the Attach button, dig for your drawing, then click Send. Just make sure is a
small drawing, no big stuff inside, just some layers, because otherwise it's
going to slow down people trying to open it.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I
must be inept because I can't upload a drawing.
Message 7 of 15
cornishrs
in reply to: joshua_sieglaff

did this lisp work properly? I can't get it to work. My prefix's contain letters, numbers, dashes, and brackets.

Thanks,
Robin
Message 8 of 15

I have resolved to write something myself and walk through the problem. When I get it fine tuned and working properly I will post it on here for everyone to enjoy. So far....it's a pretty long chunk of lisp.

Thanks for all the help.
Message 9 of 15

I can't take credit for this, but it does work well for me. I also posted the lisp file incase it gets scrambled when i post this message




(defun c:BindFix15


;/////////////////////////////////////////////////////////////////////////
;
; BindFix15.lsp (AutoCAD 2000+)
;
; Copyright 2003 | Michael Puckett | All Rights Reserved
;

;/////////////////////////////////////////////////////////////////////////

( /
; local defuns
__GetTableEntries
__RenameTableEntry
__RenameTableEntryViaObjname
__RenameTableEntryViaActiveX
__StripBindingArtifacts
__GetUniqueTableEntryName
; local vars
doc
newname
)


;/////////////////////////////////////////////////////////////////////////
;
; local defun
;

;/////////////////////////////////////////////////////////////////////////

(defun __GetTableEntries ( table / data result )
(while (setq data (tblnext table (null data)))
(setq result
(cons (cdr (assoc 2 data)) result)
)
)
result
)


;/////////////////////////////////////////////////////////////////////////
;
; local defun
;

;/////////////////////////////////////////////////////////////////////////

(defun __RenameTableEntry ( doc table oldname newname / data )
; wrapper for __RenameTableEntryViaObjname
; and __RenameTableEntryViaActiveX functions
(setq table
(cond
((eq (setq table (strcase table t)) "ltype") "linetype")
(t table)
)
)
(if (member table '("style" "dimstyle"))
; autodesk made textstyles and dimstyles read-only to
; the automation model w/regards to the symbol name, why?
(__RenameTableEntryViaObjname table oldname newname)
(__RenameTableEntryViaActiveX doc table oldname newname)
)
)


;/////////////////////////////////////////////////////////////////////////
;
; local defun
;

;/////////////////////////////////////////////////////////////////////////

(defun __RenameTableEntryViaObjname ( table oldname newname / data )
; calling function responsible for
; ensuring appropriate data passed
(entmod
(subst
(cons 2 newname)
(assoc 2 (setq data (entget (tblobjname table oldname))))
data
)
)
)


;/////////////////////////////////////////////////////////////////////////
;
; local defun
;

;/////////////////////////////////////////////////////////////////////////

(defun __RenameTableEntryViaActiveX ( doc table oldname newname / data )
; calling function responsible for
; ensuring appropriate data passed
(vla-put-name
(vla-item
(eval
(list
(read (strcat "vla-get-" table "s"))
doc
)
)
oldname
)
newname
)
; if you wanted this to be more robust
; you could use the following ...
;
; (vl-catch-all-apply
; (function
; (lambda ()
; (vla-put-name ...)
; )
; )
; )
;
; I chose to pass valid data instead
)


;/////////////////////////////////////////////////////////////////////////
;
; local defun
;

;/////////////////////////////////////////////////////////////////////////

(defun __StripBindingArtifacts ( entry / i done )
(cond
( (wcmatch entry "*`$#`$*")
(setq i 0 ceiling (strlen entry))
(while (and (not done) (< i ceiling))
(if (wcmatch (substr entry (setq i (1+ i)) 3) "`$#`$*")
(setq
entry (substr entry (+ i 3))
done t
)
)
)
)
)
entry
)


;/////////////////////////////////////////////////////////////////////////
;
; local defun
;

;/////////////////////////////////////////////////////////////////////////

(defun __GetUniqueTableEntryName ( table entry )
(cond
( (tblsearch table entry)
(setq i 1)
(while
(tblsearch table
(strcat entry "_" (itoa (setq i (1+ i))))
)
)
(strcat entry "_" (itoa i))
)
( t entry )
)
)


;/////////////////////////////////////////////////////////////////////////
;
; "main"
;

;/////////////////////////////////////////////////////////////////////////

(cond

( (< 14 (atoi (getvar "acadver")))

(vl-load-com)

(setq doc (vla-get-activedocument (vlax-get-acad-object)))

(foreach table '("block" "dimstyle" "layer" "ltype" "style")
(foreach entry (reverse (__GetTableEntries table))
(cond
( (wcmatch entry "*`$#`$*")
(__RenameTableEntry
doc
table
entry
(setq newname
(__GetUniqueTableEntryName table
(__StripBindingArtifacts entry)
)
)
)
(princ
(strcat "\n"
(if (tblsearch table newname)
(strcat
"Renamed "
table " "
entry " => "
newname "."
)
(strcat
"Could not rename "
table " "
entry "."
)
)
)
)
)
)
)
)
)

( t (princ "\nSorry, penned for AutoCAD 2000+."))

)

(princ)

)
Message 10 of 15
FraserF76
in reply to: ASCunningham

'RENAME' command

 

Layer

 

(asssume prefix is 'XYZ$' )

 

XYZ$ **

 

**

 

walah !

Message 11 of 15
scot-65
in reply to: joshua_sieglaff

Have the person doing the binding before sending to set BINDTYPE to 1.

 

 
(defun c:XRB () (setvar "BINDTYPE" 1)(command "-Xref" "Bind" "*")(princ))

-or- If part of the cleaning tool, add as one of the first items...

(c:XRB)

 

Verify your PGP does not have this keystroke sequence.

 

???

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 12 of 15
Kent1Cooper
in reply to: FraserF76


@FraserF76 wrote:

'RENAME' command

 

Layer

 

(asssume prefix is 'XYZ$' )

 

XYZ$ **

 

**

 

walah !


... unless, of course, there is already any Layer in the drawing with any of the same names minus that prefix.  That will cause a "Duplicate new name specified" error.

 

[And by the way, the expression is "voila!"]

Kent Cooper, AIA
Message 13 of 15

It works, thank you very much.

Message 14 of 15

works!
Message 15 of 15

@ASCunningham @Kent1Cooper In BindFix15, instead of renaming duplicate layers with incremental suffixes, can those layers be merged into the original layer?

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

”Boost