Author Topic: Special Layer translate LIST requred  (Read 8656 times)

0 Members and 1 Guest are viewing this topic.

sjeveni

  • Guest
Re: Special Layer translate LIST requred
« Reply #15 on: December 31, 2011, 08:40:04 AM »
Well Crank.... we need to start somewhere, right?
Will try that on Monday and inform you how it went.
Thank you.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Special Layer translate LIST requred
« Reply #16 on: December 31, 2011, 10:10:24 AM »
Give this a try as well  :-D

Code: [Select]
(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)
« Last Edit: January 04, 2012, 09:27:44 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

hmspe

  • Bull Frog
  • Posts: 362
Re: Special Layer translate LIST requred
« Reply #17 on: December 31, 2011, 10:25:22 AM »
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...

"Science is the belief in the ignorance of experts." - Richard Feynman

hmspe

  • Bull Frog
  • Posts: 362
Re: Special Layer translate LIST requred
« Reply #18 on: December 31, 2011, 05:36:24 PM »
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.
"Science is the belief in the ignorance of experts." - Richard Feynman

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Special Layer translate LIST requred
« Reply #19 on: December 31, 2011, 09:51:07 PM »
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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Special Layer translate LIST requred
« Reply #20 on: January 01, 2012, 07:01:51 AM »
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, as recommended by hmspe in an earlier post deals with table entries other than Layers.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Special Layer translate LIST requred
« Reply #21 on: January 01, 2012, 07:27:42 AM »
Tim's post here, 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? Sorry all, missed it.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Crank

  • Water Moccasin
  • Posts: 1503
Re: Special Layer translate LIST requred
« Reply #22 on: January 01, 2012, 07:35:59 AM »
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, 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?
Vault Professional 2023     +     AEC Collection

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Special Layer translate LIST requred
« Reply #23 on: January 01, 2012, 09:11:29 AM »
Tim's post here, 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? Sorry all, missed it.

No worries, after re-reading my post, I realise it was a little patronising - not intended.

hmspe

  • Bull Frog
  • Posts: 362
Re: Special Layer translate LIST requred
« Reply #24 on: January 01, 2012, 09:48:52 AM »
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.
"Science is the belief in the ignorance of experts." - Richard Feynman

Crank

  • Water Moccasin
  • Posts: 1503
Re: Special Layer translate LIST requred
« Reply #25 on: January 01, 2012, 11:30:01 AM »
[...]
Crank, I'd be interested in seeing what you use to merge text styles.[...]
I'm using a modified version of Tim's MergeTextStyles (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.
Vault Professional 2023     +     AEC Collection

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Special Layer translate LIST requred
« Reply #26 on: January 01, 2012, 02:02:57 PM »
… 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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

sjeveni

  • Guest
Re: Special Layer translate LIST requred
« Reply #27 on: January 02, 2012, 03:00:11 AM »
will need to check that on Monday....
Happy New Year everybody :D

Nothing. Layers were not renamed.

sjeveni

  • Guest
Re: Special Layer translate LIST requred
« Reply #28 on: January 02, 2012, 03:07:02 AM »
@ 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

sjeveni

  • Guest
Re: Special Layer translate LIST requred
« Reply #29 on: January 02, 2012, 03:23:18 AM »
Give this a try as well  :-D

Code: [Select]
(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


???