Author Topic: Layer 0 attack  (Read 17328 times)

0 Members and 1 Guest are viewing this topic.

Notsober

  • Guest
Layer 0 attack
« on: November 17, 2008, 05:52:22 PM »
Hi all... I know some of you won't like this, but I need a huge favor. My company is not listening to me, they don't want to spend the money, they don't want to bill the client 40 hours per dwg to simplify these P&ID's (process migration).

So, I'm looking for a lisp routine that will go into a given dwg, and strip it of ALL layers except 0. But not only that, but ALL the properties including colors, linetypes, and lineweights have to remain unchanged! This includes ALL blocks and nested blocks, and their attributes. ALL existing layers EXCEPT 0 have to go.

Is anyone up for the challenge? Please..........???

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Layer 0 attack
« Reply #1 on: November 17, 2008, 06:40:11 PM »
My company <snip> don't want to spend the money <snip> don't want to bill the client 40 hours per dwg to simplify these P&ID's (process migration) <snip> Is anyone up for the challenge? Please ... ???

Aside from the horrors of the "work", I don't why you're bothering to pursue this when you have neither the approval or the mandate. Are you going to subsidize the company on your own time, on your ticket, and are asking for people to climb aboard the fail ship? Sorry if that sounds harsh but this sounds wack at my computer.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Notsober

  • Guest
Re: Layer 0 attack
« Reply #2 on: November 17, 2008, 06:54:07 PM »
basically, I'm trying to save my job ass here. What they want me to do is not what I want to do, but I feel like I'm HAVING to do it, or I can go look for another job. See, around here engineering is slowing down, so they look for odd ended jobs to keep us going (keep us off overhead) until bigger jobs come along.

I feel the same way you do. But I'm at my wits end when I really don't know how else to do what they're intending to desire as an end product. I personally believe they are making me mangle and shred these drawings to pieces. But what should I care? If the client is willing to pay for it, then by all means. It doesn't matter what and how we do things normally. This is not a normal situation. Problem is, only that it takes a long time to strip each dwg, then plug in the desired processes. I figured I could at least save myself some time by having a routine that help me do what I want to do.

So in closing: What does it matter to you WHY i'm doing this? They know I'm stripping the dwg of all the layers. That's what they want. I simply don't know how to do it more effectively than the way I'm doing it now...

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Layer 0 attack
« Reply #3 on: November 17, 2008, 07:04:54 PM »
This should work ( not tested ).  If not, it is close to what you want.  It can be called from ObjectDBX.  If you want, a purge can be added, or a delete of all the layer records after.  But I'll leave that to you.   :wink:

Code: [Select]
(defun ChangeAllItemsToLayer0 (doc)
   
    (vlax-for i (vla-get-Layers doc)
        (vla-put-Lock i :vlax-false)
    )
    (vlax-for blk (vla-get-Blocks doc)
        (vlax-for i blk
            (vla-put-Layer i "0")
            (if (= (vla-get-ObjectName i) "AcDbBlockReference")
                (foreach j (append (vlax-invoke i 'GetAttributes) (vlax-invoke i 'GetConstantAttributes))
                    (vla-put-Layer j "0")
                )
            )
        )
    )
)

To call in the current drawing.
Code: [Select]
(ChangeAllItemsToLayer0 (vla-get-ActiveDocument (vlax-get-Acad-Object)))
Tim

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

Please think about donating if this post helped you.

Notsober

  • Guest
Re: Layer 0 attack
« Reply #4 on: November 17, 2008, 07:19:18 PM »
okay awesome.

I was just over at CADTutor, was gonna find out HOW to go about asking, the right way, someone to write a lisp for me  :wink:

i wish i had the time to really learn it  :|  I know I would enjoy it.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Layer 0 attack
« Reply #5 on: November 17, 2008, 07:23:27 PM »
If you're forcing everything to layer "0" AND you don't want the colors and line types to change doesn't that mean you have to hard code the entity's colors and line types by examining the entity's layer properties, hard coding said properties accordingly? Or do I misunderstand the requirement noted in the first post?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Notsober

  • Guest
Re: Layer 0 attack
« Reply #6 on: November 17, 2008, 07:25:20 PM »
testing now...

This should work ( not tested ).  If not, it is close to what you want.  It can be called from ObjectDBX.  If you want, a purge can be added, or a delete of all the layer records after.  But I'll leave that to you.   :wink:

Code: [Select]
(defun ChangeAllItemsToLayer0 (doc)
   
    (vlax-for i (vla-get-Layers doc)
        (vla-put-Lock i :vlax-false)
    )
    (vlax-for blk (vla-get-Blocks doc)
        (vlax-for i blk
            (vla-put-Layer i "0")
            (if (= (vla-get-ObjectName i) "AcDbBlockReference")
                (foreach j (append (vlax-invoke i 'GetAttributes) (vlax-invoke i 'GetConstantAttributes))
                    (vla-put-Layer j "0")
                )
            )
        )
    )
)

To call in the current drawing.
Code: [Select]
(ChangeAllItemsToLayer0 (vla-get-ActiveDocument (vlax-get-Acad-Object)))

Notsober

  • Guest
Re: Layer 0 attack
« Reply #7 on: November 17, 2008, 07:26:52 PM »
If you're forcing everything to layer "0" AND you don't want the colors and line types to change doesn't that mean you have to hard code the entity's colors and line types by examining the entity's layer properties, hard coding said properties accordingly? Or do I misunderstand the requirement noted in the first post?

yes pretty much is what i'm having to do now, only "manually" as opposed to automated...

Notsober

  • Guest
Re: Layer 0 attack
« Reply #8 on: November 17, 2008, 07:30:55 PM »
...or ... what exactly do you mean by "hard code"?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Layer 0 attack
« Reply #9 on: November 17, 2008, 07:35:04 PM »
If you're forcing everything to layer "0" AND you don't want the colors and line types to change doesn't that mean you have to hard code the entity's colors and line types by examining the entity's layer properties, hard coding said properties accordingly? Or do I misunderstand the requirement noted in the first post?
If this is true, it wouldn't be too hard to add.

What Michael means is that if the entity is on layer1, and layer1 color = 1, and layer1 linetype = hidden, and layer 0 color = 7, and layer 0 linetype = continuous, then once you change the layer, the entity will have color = 7 and linetype = continuous, because that is what the layer says ( if the entity's color and linetype are bylayer ).  Or should the entity's color = 1 and linetype = hidden?
Tim

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

Please think about donating if this post helped you.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Layer 0 attack
« Reply #10 on: November 17, 2008, 07:36:39 PM »
How about something like this:

Code: [Select]
(defun makesmecry (obj / p)
  (foreach p '(Color Linetype Lineweight)
    (if (vl-position (vlax-get-property obj p) '(256 -1 "ByLayer"))
      (vl-catch-all-apply
'vlax-put-property
(list obj
      p
      (vlax-get-property
(vlax-ename->vla-object
  (tblobjname "layer" (vla-get-layer obj))
)
p
      )
)
      )
    )
  )
  (vl-catch-all-apply
    'vlax-put-property
    (list obj 'Layer "0")
  )
  (princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Notsober

  • Guest
Re: Layer 0 attack
« Reply #11 on: November 17, 2008, 07:40:00 PM »
If you're forcing everything to layer "0" AND you don't want the colors and line types to change doesn't that mean you have to hard code the entity's colors and line types by examining the entity's layer properties, hard coding said properties accordingly? Or do I misunderstand the requirement noted in the first post?
If this is true, it wouldn't be too hard to add.

What Michael means is that if the entity is on layer1, and layer1 color = 1, and layer1 linetype = hidden, and layer 0 color = 7, and layer 0 linetype = continuous, then once you change the layer, the entity will have color = 7 and linetype = continuous, because that is what the layer says ( if the entity's color and linetype are bylayer ).  Or should the entity's color = 1 and linetype = hidden?

well yeah. that's why it's so complex... and the very reason why it's a challenge. Because regardless of why I need a fine tool like this, someone later on down the road might need something like this too  :wink:

and frankly, i'm quite tired of people's ruthless addiction to having blocks within blocks within blocks, and different properties for each of them!! GD!

Notsober

  • Guest
Re: Layer 0 attack
« Reply #12 on: November 17, 2008, 07:41:21 PM »
you do realize that you can post any kind of code, and i have no idea what it's gonna do?

i just know how to execute it. how scary is that?

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Layer 0 attack
« Reply #13 on: November 17, 2008, 07:45:12 PM »
you do realize that you can post any kind of code, and i have no idea what it's gonna do?

i just know how to execute it. how scary is that?

My code will grab the object layer properties if the properties are not set by object. You can plug it into Tim's code like so:

Code: [Select]
(defun ChangeAllItemsToLayer0 (doc)

  (vlax-for i (vla-get-Layers doc)
    (vla-put-Lock i :vlax-false)
  )
  (vlax-for blk (vla-get-Blocks doc)
    (vlax-for i blk
      (makesmecry i)
      (if (= (vla-get-ObjectName i) "AcDbBlockReference")
(foreach j (append (vlax-invoke i 'GetAttributes)
   (vlax-invoke i 'GetConstantAttributes)
   )
  (makesmecry j)
)
      )
    )
  )
)

*appears to work fine
« Last Edit: November 17, 2008, 08:01:45 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Notsober

  • Guest
Re: Layer 0 attack
« Reply #14 on: November 17, 2008, 08:18:55 PM »
okay hold up! wow...

i can paste all this code into one routine like this? - or is this not a lisp? if not, then i'm lost.
Code: [Select]
   
(defun ChangeAllItemsToLayer0 (vla-get-ActiveDocument (vlax-get-Acad-Object)))
   
  (vlax-for i (vla-get-Layers doc)
    (vla-put-Lock i :vlax-false)
  )
  (vlax-for blk (vla-get-Blocks doc)
    (vlax-for i blk
      (makesmecry i)
      (if (= (vla-get-ObjectName i) "AcDbBlockReference")
(foreach j (append (vlax-invoke i 'GetAttributes)
   (vlax-invoke i 'GetConstantAttributes)
   )
  (makesmecry j)
)
      )
    )
  )
)

(defun makesmecry (obj / p)
  (foreach p '(Color Linetype Lineweight)
    (if (vl-position (vlax-get-property obj p) '(256 -1 "ByLayer"))
      (vl-catch-all-apply
'vlax-put-property
(list obj
      p
      (vlax-get-property
(vlax-ename->vla-object
  (tblobjname "layer" (vla-get-layer obj))
)
p
      )
)
      )
    )
  )
  (vl-catch-all-apply
    'vlax-put-property
    (list obj 'Layer "0")
  )
  (princ)
)