Author Topic: top level xref in model space  (Read 9460 times)

0 Members and 1 Guest are viewing this topic.

Robert_s

  • Guest
top level xref in model space
« on: November 05, 2007, 10:43:08 AM »
Hello,

With Lisp/Vlisp is there a way to get the top most level/Parent xref in "Model space". We
usually only have one xref in model space (but is nested) without selecting the xref? (We
also only have one xref in Paper space and that would be the Titble block).

I just need to know the parent one. I dont need to know the nested ones.

Thanks,
Robert

T.Willey

  • Needs a day job
  • Posts: 5251
Re: top level xref in model space
« Reply #1 on: November 05, 2007, 11:00:08 AM »
Use 'ssget' to select all the blocks in model space, then test their block definition to see if they are xrefs.  Or you could step through the block collection (table) and see if the item is a block, and if so if it is inserted into model space.
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: 7529
Re: top level xref in model space
« Reply #2 on: November 05, 2007, 11:07:01 AM »
Give this a whirl:

Code: [Select]
(defun gettoplevelmsxrefs (/ ss lst)
  (if (setq ss (ssget "x" '((0 . "INSERT") (410 . "Model"))))
    (progn
      (setq ss (mapcar 'cadr (ssnamex ss)))
      (mapcar '(lambda (x)
(if (vlax-property-available-p
       (vlax-ename->vla-object x)
       'Path
     )
   (setq lst (cons x lst))
)
       )
      ss
      )
      lst
    )
  )
)
(gettoplevelmsxrefs)
« Last Edit: November 05, 2007, 11:13:21 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Robert_s

  • Guest
Re: top level xref in model space
« Reply #3 on: November 05, 2007, 11:19:28 AM »
Hello again,

Thank you guys. But I think I forgot to mention I am new with lisp/vlisp.
When I loaded the code it returned...

(<Entity name: 79dd60a8> <Entity name: 79dd60a8> <Entity name: 79dd60a8>)

I was hoping to see the name and path of the xref. How do I extract my desired
information..name & path?

Thanks again,
Roberrt

ronjonp

  • Needs a day job
  • Posts: 7529
Re: top level xref in model space
« Reply #4 on: November 05, 2007, 11:27:08 AM »
Try this Robert:

Code: [Select]
(defun gettoplevelmsxrefs (/ ss lst)
  (if (setq ss (ssget "x" '((0 . "INSERT") (410 . "Model"))))
    (progn
      (setq ss (mapcar 'cadr (ssnamex ss)))
      (mapcar '(lambda (x)
(if (vlax-property-available-p
       (vlax-ename->vla-object x)
       'Path
     )
   (setq lst (cons (vlax-ename->vla-object x) lst))
)
       )
      ss
      )
      (if lst
(mapcar
  '(lambda (x)
     (princ (strcat "\nName: " (vla-get-name x) " - Path: " (vla-get-path x))
     )
   )
  lst
)
      )
      lst
    )
  )
)
(gettoplevelmsxrefs)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Robert_s

  • Guest
Re: top level xref in model space
« Reply #5 on: November 05, 2007, 11:36:12 AM »
Hi,

Almost there! Can you please make it return in a list form?

For example.
if one xref.... ("p:\\projects\\xref\\plan1.dwg")
if two xrefs ..("p:\\projects\\xref\\plan1.dwg" "p:\\projects\\xref\\plan2.dwg")

Thanks
Robert

ronjonp

  • Needs a day job
  • Posts: 7529
Re: top level xref in model space
« Reply #6 on: November 05, 2007, 11:41:46 AM »
Hi,

Almost there! Can you please make it return in a list form?

For example.
if one xref.... ("p:\\projects\\xref\\plan1.dwg")
if two xrefs ..("p:\\projects\\xref\\plan1.dwg" "p:\\projects\\xref\\plan2.dwg")

Thanks
Robert

This will return a list like this ("path1" "path2" "path3").... What are you going to do with this list?

Code: [Select]
(defun gettoplevelmsxrefs (/ ss lst)
  (if (setq ss (ssget "x" '((0 . "INSERT") (410 . "Model"))))
    (progn
      (setq ss (mapcar 'cadr (ssnamex ss)))
      (mapcar '(lambda (x)
(if (vlax-property-available-p
       (vlax-ename->vla-object x)
       'Path
     )
   (setq lst
  (cons (vla-get-path (vlax-ename->vla-object x)) lst)
   )
)
       )
      ss
      )
      lst
    )
  )
)
(gettoplevelmsxrefs)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Robert_s

  • Guest
Re: top level xref in model space
« Reply #7 on: November 05, 2007, 12:07:57 PM »
Hi,

Yes! yes! yes!. This is exactly what I needed!

Like I said I am new with lisp/vlisp. But I want to write a code using
ObjectDbx.  I want to update my Plot sheets layers.

When users in my office work on drawings that are being xref to plot
sheets. They freeze layers and sometimes change layer colors. But
when they open up their respective plot sheet it does not update the
layers. And we get into a lot of trouble with each submission. Cause
we only open the plot sheet when we are ready to plot.

When you open a plot sheet. Without the user knowing...
1. I want to know the parent xref/s in model space.
2. Open that xref/s drawing with ObjectDbx and collect the layer settings.
3. Update the layer settings of the opened plot sheet to reflect/update/match
    with the xref drawing.

Of course if you feel like coding it yourself I wont stop you (Hint..hint). 

Thank you very much!
Robert,






T.Willey

  • Needs a day job
  • Posts: 5251
Re: top level xref in model space
« Reply #8 on: November 05, 2007, 12:11:58 PM »
3. Update the layer settings of the opened plot sheet to reflect/update/match
    with the xref drawing.
See if the routine here is something that will help you.
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: 7529
Re: top level xref in model space
« Reply #9 on: November 05, 2007, 12:35:26 PM »
Wouldn't setting VISRETAIN to 0 do what you want without code?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

T.Willey

  • Needs a day job
  • Posts: 5251
Re: top level xref in model space
« Reply #10 on: November 05, 2007, 01:08:03 PM »
Wouldn't setting VISRETAIN to 0 do what you want without code?
But that will turn on and freeze the layers per the xref also.  Just an FYI.
Tim

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

Please think about donating if this post helped you.

Robert_s

  • Guest
Re: top level xref in model space
« Reply #11 on: November 05, 2007, 01:09:09 PM »
Hi Tim,

I tried the code "SetOrigLayerProps" on Autocad 2006 & Autocad 2008.
In 2008 I changed the line.. (if (< (atoi (setq oVer (substr (getvar "acadver") 1 2))) 16)..from 16 to 17.

I tried using the code on the plot sheet and it gave me this error:..

Single layer, or All layers <S>:
Select object within Xref to copy back original layer properties: error:
Automation Error. Key not found

Then it made the parent xref a read only file. But you what. This can serve as a sample coding for me.
Thanks for the link.

And Ron (sorry, did I get your first name right?), setting visretain to 0 will not work. The parent xref also has
parent * nested xrefs. The Plot sheet will reflect the 2nd level set of xrefs (the ones being xref into the parent xref).
What I am trying to say is that with visretain set to 0, Plot sheet will update to layer settings of the "xrefs"
of parent drawing NOT the layer settings of "parent" drawing. Whoo! I hope you understood what I just said.


Thanks again guys,
Robert

T.Willey

  • Needs a day job
  • Posts: 5251
Re: top level xref in model space
« Reply #12 on: November 05, 2007, 01:16:10 PM »
No need to change any line, as it works on '08 (I just tested it).  Put it back, and try again.
Tim

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

Please think about donating if this post helped you.

Robert_s

  • Guest
Re: top level xref in model space
« Reply #13 on: November 05, 2007, 01:40:02 PM »
Tim,

I must be doing something wrong or I am not understanding how
the sequence of prompts.

I went back to the link, copy & paste it to a new lsp.
1.  Open Plot sheet.
2.  Went to model space.tilemode 1
3.  Loaded and called SetOrigLayerProps.lsp
4.  Command: Single layer, or All layers <S>
5.  If I hit Enter or Key-in "S"
    Select object within Xref to copy back original layer properties: error:
    Automation Error. Key not found
6. If I key-in A for All
   Select object within Xref to copy back original layer properties: .....I select part of parent xref..it prompts me again
   Select object within Xref to copy back original layer properties:......what do i do next?
 

T.Willey

  • Needs a day job
  • Posts: 5251
Re: top level xref in model space
« Reply #14 on: November 05, 2007, 01:43:27 PM »
Tim,

I must be doing something wrong or I am not understanding how
the sequence of prompts.

I went back to the link, copy & paste it to a new lsp.
1.  Open Plot sheet.
2.  Went to model space.tilemode 1
3.  Loaded and called SetOrigLayerProps.lsp
4.  Command: Single layer, or All layers <S>
5.  If I hit Enter or Key-in "S"
    Select object within Xref to copy back original layer properties: error:
    Automation Error. Key not found
6. If I key-in A for All
   Select object within Xref to copy back original layer properties: .....I select part of parent xref..it prompts me again
   Select object within Xref to copy back original layer properties:......what do i do next?
 

What you want is the 'all' option, so 'a' is okay.  You might be selecting a nested item inside the xref.  I don't I coded for that since I don't use nested xrefs.  After you hit 'all' and pick a point, hit enter to exit the command.  Does it not show the correct color and linetype for the layers in the main xref?
Tim

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

Please think about donating if this post helped you.

Robert_s

  • Guest
Re: top level xref in model space
« Reply #15 on: November 05, 2007, 01:54:49 PM »
Tim,

No. Nothing happens. I think it does not recognized the entity I selected.
Told you, my parent block is nested to the nth degree.

Robert,

T.Willey

  • Needs a day job
  • Posts: 5251
Re: top level xref in model space
« Reply #16 on: November 05, 2007, 02:01:44 PM »
Run this, and post a pic of what is in the alert box.  This will help figure out what is happening.
Code: [Select]
(defun c:NList (/ Sel EntList Data tempType NListString)

(setq NListString "")
(if (setq Sel (nentsel "\n Select object to list properties of it, and of partent entities if nested: "))
(progn
(if (> (length Sel) 2)
(setq EntList (append (list (car Sel)) (last Sel)))
(setq EntList (list (car Sel)))
)
(foreach ent EntList
(if (equal (type ent) 'ENAME)
(progn
(setq Data (entget Ent))
(setq NListString
(strcat
NListString
"\n Entity type: "
(setq tempType (cdr (assoc 0 Data)))
(cond
(
(and
(= tempType "INSERT")
(/=
(cdr
(assoc
1
(entget
(tblobjname
"block"
(cdr
(assoc 2 Data)
)
)
)
)
)
""
)
)
(strcat
" [ Xref - "
(cdr (assoc 2 Data))
" ]"
)
)
((= tempType "INSERT")
(strcat
" [ "
(cdr (assoc 2 Data))
" ]"
)
)
(T "")
)
"\n    Layer: "
(cdr (assoc 8 Data))
"\n    Linetype: "
(if (assoc 6 Data)
(cdr (assoc 6 Data))
"ByLayer"
)
"\n    Color: "
(if (assoc 62 Data)
(itoa (cdr (assoc 62 Data)))
"ByLayer"
)
"\n"
)
)
)
)
)
(alert NListString)
)
)
(princ)
)
Tim

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

Please think about donating if this post helped you.

Robert_s

  • Guest
Re: top level xref in model space
« Reply #17 on: November 05, 2007, 02:16:44 PM »

Okay..Hope this helps.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: top level xref in model space
« Reply #18 on: November 05, 2007, 02:27:44 PM »
There will be a problem with the 'single' option, but the 'all' option should work.  The only problem that I can see is that the code will not change nested xref layer properties.  If that is what you want, then the code will need to be changed.  This line of code
Code: [Select]
(if (and (not (vl-string-search "|" LayName)) (/= LayName "0") (/= (strcase LayName) "DEFPOINTS"))is saying that if the layer name doesn't have the pipe symbol, which and xref layer would, and is not named '0' or 'defpoints' then update the layer within the current drawing to the settings of that in the xref file.

So you can use it as a guide to make your own routine to emulate how you do your drawings.

Hope it helped a little.
Tim

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

Please think about donating if this post helped you.

Robert_s

  • Guest
Re: top level xref in model space
« Reply #19 on: November 05, 2007, 02:35:46 PM »
Tim,

Thank you. Yes, I know I will learn a lot from your example.
I hope I did not take most of your time.

Many Thanks,
Robert

T.Willey

  • Needs a day job
  • Posts: 5251
Re: top level xref in model space
« Reply #20 on: November 05, 2007, 03:08:29 PM »
Tim,

Thank you. Yes, I know I will learn a lot from your example.
I hope I did not take most of your time.

Many Thanks,
Robert
You're welcome Robert.  If you run into a problem with your code, just post and I'm sure you will get some help.  There are a lot of smart people here.
Tim

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

Please think about donating if this post helped you.

Robert_s

  • Guest
Re: top level xref in model space
« Reply #21 on: November 06, 2007, 02:43:23 PM »
Hello again,

Quick question with lisp..Is there a quick & easy way to thaw and turn on all the layers in
"Model Space" only?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: top level xref in model space
« Reply #22 on: November 06, 2007, 03:00:21 PM »
Don't know what you mean by "Model space only".  Once you thaw or turn on a layer it is affected in the whole drawing, unless it is frozen or off within a viewport.
Tim

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

Please think about donating if this post helped you.

Robert_s

  • Guest
Re: top level xref in model space
« Reply #23 on: November 06, 2007, 03:19:38 PM »
Hi Tim,

In the Plot Sheet, I want to  first thaw & turn on first all the layers of the Parent Xref drawing (which
is located in model space). Before I apply the layer settings (the ones that are frozen & turned off collected
with ObjectDbx).

In paper space I have my title block drawing. There may be some layers frozen (ex. Key Plan, graphic scale..)
I want them to remain frozen/off.

Did I make sense?


T.Willey

  • Needs a day job
  • Posts: 5251
Re: top level xref in model space
« Reply #24 on: November 06, 2007, 03:59:28 PM »
You could step through the model space block definition and collect a list of all the layers that are assigned, but I would think that would take a long time because then you would have to step through each block definition, and see if they have attributes associated with the inserted block.  If you are only concerned about the xref layers, then that should be easy enough.
Tim

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

Please think about donating if this post helped you.

Robert_s

  • Guest
Re: top level xref in model space
« Reply #25 on: November 06, 2007, 04:20:14 PM »
Yeah, that was what I was afraid of. Its going to going to take time.
Oh well. Thanks again Tim.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: top level xref in model space
« Reply #26 on: November 06, 2007, 05:01:06 PM »
The code wouldn't be hard to write.  So you could test it to see if it takes too much time, because maybe it won't take that much.  I don't want to scare you about time because it depends on what items you have in model space, and how many.

You're welcome Robert.
Tim

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

Please think about donating if this post helped you.

Robert_s

  • Guest
Re: top level xref in model space
« Reply #27 on: November 06, 2007, 05:45:51 PM »
Tim,

A thought just occured to me as I was driving home. Instead of "stepping through the model space block definition".
I will step through the "Paper Space" block definition. Since I know it has only one block/xref (the title block) and it
its not nested. It may only have 10 layers at the most.

Things are looking up. Now I have go fishing for the code.


Robert


T.Willey

  • Needs a day job
  • Posts: 5251
Re: top level xref in model space
« Reply #28 on: November 06, 2007, 05:53:30 PM »
Just make sure you step through all paper space tabs then, but it sounds like it could be a good idea.
Tim

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

Please think about donating if this post helped you.

Robert_s

  • Guest
Re: top level xref in model space
« Reply #29 on: November 06, 2007, 06:00:02 PM »
Good point. Fortunately our office policy is only one layout tab per drawing.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: top level xref in model space
« Reply #30 on: November 06, 2007, 06:04:07 PM »
Good point. Fortunately our office policy is only one layout tab per drawing.
So is ours, but our consultants don't always follow our standard.   :-)
Tim

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

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: top level xref in model space
« Reply #31 on: November 06, 2007, 06:26:56 PM »
I had a minute, so here is the code to get the layers per model space.  Now don't look if you don't want to see the code yet.

Edit:  Updated code.  Wrong syntax on my part.






Code: [Select]
(defun LayListModelSpace (Doc / LayNameList BlkNameList GetBlockLayers)

(defun GetBlockLayers (BlkDefObj BlkCol)

(vlax-for obj BlkDefObj
(if (not (vl-position (vla-get-Layer obj) LayNameList))
(setq LayNameList (cons (vla-get-Layer obj) LayNameList))
)
(if (= (vla-get-ObjectName obj) "AcDbBlockReference")
(progn
(foreach att (append (vlax-invoke obj 'GetAttributes) (vlax-invoke obj 'GetConstantAttributes))
(if (not (vl-position (vla-get-Layer att) LayNameList))
(setq LayNameList (cons (vla-get-Layer att) LayNameList))
)
)
(if (not (vl-position (vla-get-Name obj) BlkNameList))
(progn
(GetBlockLayers
(vla-Item BlkCol (vla-get-Name obj))
BlkCol
)
(setq BlkNameList (cons (vla-get-Name obj) BlkNameList))
)
)
)
)
)
LayNameList
)

(GetBlockLayers (vla-get-ModelSpace Doc) (vla-get-Blocks Doc))
)
So for you, you would do something like
Code: [Select]
(setq LayList (LayListModelSpace dbxDoc))
since the routine wants a document object.  This will return a list of all the layer names, then you can do what you want with the list.
« Last Edit: November 06, 2007, 07:06:06 PM by T.Willey »
Tim

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

Please think about donating if this post helped you.

Robert_s

  • Guest
Re: top level xref in model space
« Reply #32 on: November 06, 2007, 07:17:01 PM »
Tim,

Thank you. I really appreciate it. I'm learning a lot already.

Robert

T.Willey

  • Needs a day job
  • Posts: 5251
Re: top level xref in model space
« Reply #33 on: November 06, 2007, 07:23:19 PM »
You're welcome Robert.  I just hope you can follow the logic.  I know when I started to read people's code who have been doing it for a while, the logic was kind of lost on me.  Maybe you will pick it up faster than I did.
Tim

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

Please think about donating if this post helped you.