TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: sjeveni on December 30, 2011, 06:44:15 AM
-
Hi everybody.
I'm new on this forum and would like to ask you for a favour.
We are facing some problems while dealing with Xref's. Few people select Bind instead of Insert command. This creats mess in our Layer system. I'm searching a List that could translate these layers back into normal ones.
Some may say, whay don't you use Layer translator? It is not sutable for the amount of layers that we need to correct.
So the problem is next:
We need to translate back in normal layers (let's cal them A-1, A-2, A-3, A-4,....) from prefix that they got while Binding and looks:
4176-X_TT$0$A-1
4176-X_TT$0$A-2
4176-X_TT$0$A-3
4176-X_TT$0$A-4
4176-X_TT$0$A-5.....
4176-X_SS$0$A-1
4176-X_SS$0$A-2
4176-X_SS$0$A-3
4176-X_SS$0$A-4
4176-X_SS$0$A-5...
....
I need that all numbers, symblos, letters.... before real Layers name dissaper.
Please note that becouse of few diferent Xref's in my drawing it is also few diferent prefix (4176-X_TT$0$ or 4176-X_SS$0$....), so list should be writen so that we can write different prefix TT or SS.
Thank you in advance
-
Welcome to the Swamp.
Some of options:
http://www.theswamp.org/index.php?topic=5835.msg71232#msg71232
http://www.theswamp.org/index.php?topic=36566.0
http://www.theswamp.org/index.php?topic=30327.msg359285#msg359285
-
Look at this thread: http://www.theswamp.org/index.php?topic=17496.msg210985#msg210985
As is noted in the thread you need to be aware that not all layers will be automatically renamed with the code in the thread. In your example if the drawing has a layer named A-1 then a layer named 4176-x_TT$0$A-1 would not be renamed. It would not be hard to add code to handle layers that would change to layer names that already exist, but you might get unwanted results unless you are sure that the layer names in both the main drawing and in the xref meet your layering standards. An example would be a main drawing with a layer named WALLS that was new construction and an xref with a layer named WALLS that was walls to be removed. Merging the data to a single layer would probably be undesirable in this case.
-
I assume what he wanted was this:
4176-X_TT$0$A-1 TT_A-1
4176-X_TT$0$A-2 TT_A-2
4176-X_TT$0$A-3 TT_A-3
4176-X_TT$0$A-4 TT_A-4
4176-X_TT$0$A-5..... TT_A-5.....
_
4176-X_SS$0$A-1 SS_A-1
4176-X_SS$0$A-2 SS_A-2
4176-X_SS$0$A-3 SS_A-3
4176-X_SS$0$A-4 SS_A-4
4176-X_SS$0$A-5... SS_A-5...
-
CAB,
Entirely possible that your interpretation is correct. The top portion of the OP says that the normal layer would be A-1, with all letters, symbols, and text before the normal layer name removed for bound layers. The last part of the OP says that some parts of the text before the normal layer name might need to be retained. The two seem to be contradictory.
Maybe sjeverni can clarify the request.
-
I appologize if I was not clear.
I need layers to be A-1, not SS_A-1.
This is the case.
Let's say that we have project no. 4176. And in the drawing we have xref for every floor (AA, BB, CC.... SS, TT....) and we have common layers A-1, A-2....
So when someone decide to "Bind" these xref instead to use "Insert" we are getting:
4176-X_TT$0$A-1
4176-X_TT$0$A-2
4176-X_TT$0$A-3 only for one floor, but then is a next floor:
4176-X_UU$0$A-1
4176-X_UU$0$A-2
4176-X_UU$0$A-3... and depends of how many floors do we have, it will be so many layers that are basicaly of the same charachteristics as the other from different floors.
So I need Lisp that will take all A-1, A-2.....K-20 layers and get ridd of:
4176-X_TT$0$ or 4176-X_UU$0$ so that all different A-1 comes into single A-1 layer.
The project number is allways the same (in this case 4176, we should have possibilities to change that depends of project number) layers are allways standards (I can fill them my self later... some cca. 20 diferent layers).
Please ask questions if you need more info.
Again, thank you very much for the any help that you can provide.
-
So to summarize … strip & merge?
-
MP,
I'm not sure what does it meens (my english is not so god) 8-)
-
Look at this thread: http://www.theswamp.org/index.php?topic=17496.msg210985#msg210985
As is noted in the thread you need to be aware that not all layers will be automatically renamed with the code in the thread. In your example if the drawing has a layer named A-1 then a layer named 4176-x_TT$0$A-1 would not be renamed. It would not be hard to add code to handle layers that would change to layer names that already exist, but you might get unwanted results unless you are sure that the layer names in both the main drawing and in the xref meet your layering standards. An example would be a main drawing with a layer named WALLS that was new construction and an xref with a layer named WALLS that was walls to be removed. Merging the data to a single layer would probably be undesirable in this case.
Hi hmspe,
maybe you are on something here.
I just want one (as you proposed) WALLS layer. And, for sure, we will have in the drawing layer called WALLS but all the rest prefixWALLS layers must be transfered into existing WALLS layer.
-
MP,
I'm not sure what does it meens (my english is not so good) 8-)
Strip (remove unwanted prefixes) & Merge (combine identical layer names).
-
Strip (remove unwanted prefixes) & Merge (combine identical layer names).
[/quote]
Yes, great.... how can we do it :)???
-
It's been done; many times. Wait 'til some one posts a link or code. I'm too tired to do either at present. Sorry.
-
So what do you get when you run this code?
http://www.theswamp.org/index.php?topic=17496.0
-
will need to check that on Monday....
Happy New Year everybody :D
-
@ CAB: That will only rename, but when a layer or linetype already exists it doesn't merge.
@ sjeverni: In my library I found the attached file, but I've to warn you that I've never tried it.
-
Well Crank.... we need to start somewhere, right?
Will try that on Monday and inform you how it went.
Thank you.
-
Give this a try as well :-D
(defun c:merge2delim (/ del doc)
(vl-load-com)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
;;Unlock all layers
(vlax-for i (vla-get-layers doc) (vlax-put i 'lock 0))
;;Drill down to last occurence of delimeter and strip text
(defun _strip (string del)
(if (vl-string-search del string)
(substr string (+ 2 (vl-string-position (ascii del) string nil t)))
string
)
)
;;Merges objects layer if found after _strip or renames _strip layer
(defun _merge (obj del / lay nlay l)
(if (and obj
(setq lay (vla-get-layer obj))
(vl-string-search del lay)
(not (zerop (strlen (setq nlay (_strip lay del)))))
)
(if (tblobjname "layer" nlay)
(vl-catch-all-apply 'vla-put-layer (list obj nlay))
(if (setq l (tblobjname "layer" lay))
(vl-catch-all-apply
'vla-put-name
(list (vlax-ename->vla-object l) (vl-string-left-trim " " nlay))
)
)
)
)
)
(repeat 2 (vla-purgeall doc))
;;Set delimeter to use here
(setq del "$")
;;Apply _merge to doc
(vlax-for b (vla-get-blocks doc)
(vl-catch-all-apply 'vla-put-name (list b (_strip (vla-get-name b) del)))
(vlax-for i b
(_merge i del)
(if (vlax-property-available-p i 'hasattributes)
(foreach a (vlax-invoke i 'getattributes) (_merge a del))
)
)
)
(repeat 2 (vla-purgeall doc))
;;One last check for layer names with delimeter in them and attempt to rename
(vlax-for i (vla-get-layers doc)
(if (vl-string-search del (vla-get-name i))
;;(vl-catch-all-apply 'vla-put-name (list i (_strip (vla-get-name i) del)))
(command "-LAYMRG" "_Name" (vla-get-name i) "" "_Name" (_strip (vla-get-name i) del) "_Yes")
)
)
(repeat 2 (vla-purgeall doc))
(princ)
)
;;(c:merge2delim)
-
If you want to use a lisp solution it would be easy to take Alan's code in post #4 at
http://www.cadtutor.net/forum/showthread.php?46009-Transfer-all-objects-from-one-layer-to-another
and add it to the routine that CAB linked to in post #12. The concept would be to replace the "was not renamed" lines with calls to Alan's routine. Alan's routine would need to be modified to allow data to be passed in instead of requiring manual selection. This should be similar to the operation of the VBA routine Crank posted.
Or you could try ronjonp's routine that he posted while I was writing this...
-
Another option is the code in post #27 here: http://forums.augi.com/showthread.php?t=31759&page=3
This routine uses LAYMRG from the express tools so the results are a bit different from the other routines posted above. See also post #30 for comments on styles.
-
Ya'll should keep in mind it's possible the OP isn't indicating the full requirements of this thread's request: when binding xrefs all table entries (e.g. layers, text styles yada) inherit the *$0$* sh!t. Subtitle: the intelligent stripping / merging may have to be performed on more than just layers. I may be wrong, on the other hand, I may be wrong. (http://www.theswamp.org/screens/mp/oh.gif)
-
Ya'll should keep in mind it's possible the OP isn't indicating the full requirements of this thread's request: when binding xrefs all table entries (e.g. layers, text styles yada) inherit the *$0$* sh!t.
Tim's post here (http://www.theswamp.org/index.php?topic=17496.msg210835#msg210835), as recommended by hmspe in an earlier post deals with table entries other than Layers.
-
Tim's post here (http://www.theswamp.org/index.php?topic=17496.msg210835#msg210835), as recommended by hmspe in an earlier post deals with table entries other than Layers.
Does this mean I shouldn't post when I'm half cut? (http://www.theswamp.org/screens/mp/facepalm.gif) Sorry all, missed it.
-
Ya'll should keep in mind it's possible the OP isn't indicating the full requirements of this thread's request: when binding xrefs all table entries (e.g. layers, text styles yada) inherit the *$0$* sh!t.
Tim's post here (http://www.theswamp.org/index.php?topic=17496.msg210835#msg210835), as recommended by hmspe in an earlier post deals with table entries other than Layers.
Yes, but when renaming the table isn't possible because the table already exsists, it doesn't merge with that table. None of the lisp routines posted here is a complete solution.
For layers you could use the LAYMRG command and I've already something for merging text styles. Dimstyles or mleaderstyles can be updated, but I've never seen a lisp file to merge linetypes... Is there such a thing?
-
Tim's post here (http://www.theswamp.org/index.php?topic=17496.msg210835#msg210835), as recommended by hmspe in an earlier post deals with table entries other than Layers.
Does this mean I shouldn't post when I'm half cut? (http://www.theswamp.org/screens/mp/facepalm.gif) Sorry all, missed it.
No worries, after re-reading my post, I realise it was a little patronising - not intended.
-
I haven't found anything to merge line types, at least so far.
Crank, I'd be interested in seeing what you use to merge text styles. With all the custom styles that just happen to have identical names, and with the users who "make their lives easy by setting the STANDARD style to their preferred font" merging text styles could be problematic.
As Tim noted in thread 17496 his code does not merge styles and it leaves behind the styles (and associated layers) that could could not be renamed. irneb's code from AUGI uses LAYMRG. LAYMRG does not leave behind any layers with $0$, but it does leave styles with $0$.
The code for LAYMRG was clear text back around 2004 (and can be found on Google, file name lydelmrg.lsp). It might be interesting to try to modernize that code.
-
[...]
Crank, I'd be interested in seeing what you use to merge text styles.[...]
I'm using a modified version of Tim's MergeTextStyles (http://www.theswamp.org/index.php?topic=17659.0) (Thank's Tim).
To be more consistant with AutoCAD, I renamed it to STYLETRANS and changed the layout of the dialogbox so it would look more like the LAYTRANS command.
In the DCL the part for the system variables was hidden, because I think it doesn't belong there (code was not removed, so you can activate it again in the DCL).
Also support for annotative textstyles was added.
-
… after re-reading my post, I realise it was a little patronising - not intended.
Not the way I took it, I just regret buggering up the signal to noise ratio; cheers.
-
will need to check that on Monday....
Happy New Year everybody :D
Nothing. Layers were not renamed.
-
@ CAB: That will only rename, but when a layer or linetype already exists it doesn't merge.
@ sjeverni: In my library I found the attached file, but I've to warn you that I've never tried it.
getting error message: VBA-not installed
-
Give this a try as well :-D
(defun c:merge2delim (/ del doc)
(vl-load-com)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
;;Unlock all layers
(vlax-for i (vla-get-layers doc) (vlax-put i 'lock 0))
;;Drill down to last occurence of delimeter(s) and strip text
(defun _strip (string del / d+ nlay p)
(if (setq p (vl-string-search del string))
(progn (setq d+ (1+ (strlen del)))
(setq nlay (substr string (+ p d+)))
(while (setq p (vl-string-search del nlay)) (setq nlay (substr nlay (+ p d+))))
nlay
)
string
)
)
;;Merges objects layer if found after _strip or renames _strip layer
(defun _merge (obj del / lay nlay)
(if (and obj (setq lay (vla-get-layer obj)) (vl-string-search del lay))
(if (not (zerop (strlen (setq nlay (_strip lay del)))))
(if (tblobjname "layer" nlay)
(vla-put-layer obj nlay)
(vla-put-name
(vlax-ename->vla-object (tblobjname "layer" lay))
(vl-string-left-trim " " nlay)
)
)
)
)
)
;;Set delimeter to use here
(setq del "$0$")
;;Apply _merge to doc
(vlax-for b (vla-get-blocks doc)
(vlax-for i b
(_merge i del)
(if (vlax-property-available-p i 'hasattributes)
(foreach a (vlax-invoke i 'getattributes) (_merge a del))
)
)
)
(repeat 2 (vla-purgeall doc))
;;One last check for layer names with delimeter in them and attempt to rename
(vlax-for i (vla-get-layers doc)
(if (vl-string-search del (vla-get-name i))
(vl-catch-all-apply 'vla-put-name (list i (_strip (vla-get-name i) del)))
)
)
(repeat 2 (vla-purgeall doc))
(princ)
)
(c:merge2delim)
Hm... I don't understand.
when I installed this lisp frst time, all went fine, it did job pefrectly. So I said to give it a try again on some other drawing and it didn't work.
So I shut down my AutoCAD and instaled lisp again and got message:
Command: _appload merge2delim.LSP successfully loaded.
Command: ; error: bad argument type: lentityp nil
Command:
Command: merge2delim
; error: bad argument type: lentityp nil
???
-
Ya'll should keep in mind it's possible the OP isn't indicating the full requirements of this thread's request: when binding xrefs all table entries (e.g. layers, text styles yada) inherit the *$0$* sh!t. Subtitle: the intelligent stripping / merging may have to be performed on more than just layers. I may be wrong, on the other hand, I may be wrong. (http://www.theswamp.org/screens/mp/oh.gif)
This One worked Fine:
(vl-load-com)
(defun c:LayerClean (/ layers lo name badlayers name1 pos)
(setvar "CLAYER" "0")
(setq layers (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))))
(vlax-for lo layers
(setq name (vla-get-Name lo))
(cond
((and (vl-string-search "$" name) (not (vl-string-search "|" name)))
(setq badlayers (cons name badlayers))
)
)
)
(foreach name badlayers
(setq name1 name
lo (vla-Item layers name)
)
(while (setq pos (vl-string-search "$" name1))
(setq name1 (substr name1 (+ pos 2)))
)
(cond
((tblsearch "LAYER" name1)
(command "-LAYMRG" "_Name" name "" "_Name" name1 "_Yes")
)
(t
(vla-put-Name lo name1)
)
)
)
(princ)
)
Can someone edit this to include also blocks renaming.
Layers all OK now even those in Blocks. But blocks names are still with 4176-x_(something)$0$(real block name).
-
...
Hm... I don't understand.
when I installed this lisp frst time, all went fine, it did job pefrectly. So I said to give it a try again on some other drawing and it didn't work.
So I shut down my AutoCAD and instaled lisp again and got message:
Command: _appload merge2delim.LSP successfully loaded.
Command: ; error: bad argument type: lentityp nil
Command:
Command: merge2delim
; error: bad argument type: lentityp nil
Can you post a sample drawing?
**EDIT I reposted the code in the original post to include some catch-all statements. Let me know if that fixes yours errors.
-
Ronjonp,
- when I loaded lisp it did the job automatically without typing command, just when I closed Load/unload applications screen. I didn't liked that.
- when I wanted to do the same on othed drawing (by typing command) got an error message Unknown command. Strange, isn't it?
- Frst time jobe was done almost perfectlly. There was 3 or 4 layers lefted unchanged.
- Block names are lefted unchanged, could you please include in lisp cleaning of block names same as on layers (all before and including $0$).
Sending you a part of drawing that you can test on.
Best Regards,
S.
P.S. Btw. it is very fast, much faster than LayerClean lisp (althrought this one actually work on command, not by it self :D)
-
Ronjonp,
- when I loaded lisp it did the job automatically without typing command, just when I closed Load/unload applications screen. I didn't liked that.
- when I wanted to do the same on othed drawing (by typing command) got an error message Unknown command. Strange, isn't it?
- Frst time jobe was done almost perfectlly. There was 3 or 4 layers lefted unchanged.
- Block names are lefted unchanged, could you please include in lisp cleaning of block names same as on layers (all before and including $0$).
Sending you a part of drawing that you can test on.
Best Regards,
S.
P.S. Btw. it is very fast, much faster than LayerClean lisp (althrought this one actually work on command, not by it self :D)
I updated the original code to include renaming blocks and used the -laymrg at the end to check for layers not merged. Let me know how it goes :).
http://www.theswamp.org/index.php?topic=40535.15
-
Command: merge2delim
; error: Automation Error. Duplicate record name
-
Command: merge2delim
; error: Automation Error. Duplicate record name
Updated to add another catch-all ... try it again.
-
Seems to work perfectlly.
Geve me little bit more time to test it on few different drawings.
-
Seems to work perfectlly.
Geve me little bit more time to test it on few different drawings.
Good deal 8-)