Author Topic: Edit draworder with vba  (Read 5945 times)

0 Members and 1 Guest are viewing this topic.

jura

  • Guest
Edit draworder with vba
« on: August 20, 2004, 02:01:12 PM »
I was wondering if i can control the draworder by using vba. I can't seem to
find which property controls the draworder.

Something like this: (stripped down version)
Code: [Select]

Sub Block2Front()

Dim BlockSSet As AcadSelectionSet
Dim VarBlock As Variant

Set BlockSSet = ThisDrawing.SelectionSets.Add("block")
BlockSSet.SelectOnScreen

For Each VarBlock In BlockSSet
VarBlock.XXXXXXX = "Front"
Next

BlockSSet.Delete
End Sub



Thx to Devitg for pointing me to the swamp. Thought i'd lost this after
Cadalog closed the forum. What is the stoy behind that btw. Thought they
(the new owners) promised to leave the forum intact. Was it interfering too much with their commecial thoughts?

SpeedCAD

  • Guest
Re: Edit draworder with vba
« Reply #1 on: August 20, 2004, 05:50:24 PM »
Quote from: jura
I was wondering if i can control the draworder by using vba. I can't seem to
find which property controls the draworder.

Something like this: (stripped down version)
Code: [Select]

Sub Block2Front()

Dim BlockSSet As AcadSelectionSet
Dim VarBlock As Variant

Set BlockSSet = ThisDrawing.SelectionSets.Add("block")
BlockSSet.SelectOnScreen

For Each VarBlock In BlockSSet
VarBlock.XXXXXXX = "Front"
Next

BlockSSet.Delete
End Sub


Hi...

You test with SendCommand:
Code: [Select]

Sub Block2Front()

Dim BlockSSet As AcadSelectionSet
Dim VarBlock As Variant

Set BlockSSet = ThisDrawing.SelectionSets.Add("block")
BlockSSet.SelectOnScreen

ThisDrawing.SendCommand "_.draworder" & vbCr & "_p" & vbCr & vbCr & "_Front" & vbCr

BlockSSet.Delete
End Sub

jura

  • Guest
Edit draworder with vba
« Reply #2 on: August 20, 2004, 08:42:13 PM »
That's a fine solution for setting the draworder. Thx

The draworder however must be stored in a value somewhere. Is it possible to catch this value to store it in a variabel.

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Edit draworder with vba
« Reply #3 on: August 21, 2004, 12:23:25 PM »
Quote from: jura
That's a fine solution for setting the draworder. Thx

The draworder however must be stored in a value somewhere. Is it possible to catch this value to store it in a variabel.

From the DXF reference on SORTENTSTABLE:
Quote
If the SORTENTS Regen flag (bit-code value 16) is set, AutoCAD regenerates entities in ascending handle order. When the DRAWORDER command is used, a SORTENTSTABLE object is attached to the *Model_Space or *Paper_Space block's extension dictionary under the name ACAD_SORTENTS. The SORTENTSTABLE object related to this dictionary associates a different handle with each entity which redefines the order that the entities are regenerated.

It appears that the data saved in this table is NOT accessible with VBA/ActiveX. It IS available to Lisp:
Code: [Select]
(setq layouts (vla-get-layouts *doc*))
(setq ms (vla-item layouts "Model"))
(setq blk (vla-get-block ms))
(if (= :vlax-true (vla-get-hasextensiondictionary blk))
  (progn
    (setq dict (vla-getextensiondictionary blk))
    (setq item (vla-item dict 0))
    (setq ename (vlax-vla-object->ename item))
    (entget ename)
    )
  )

HTH

sinc

  • Guest
Edit draworder with vba
« Reply #4 on: August 21, 2004, 03:31:03 PM »
Why isn't that available in VBA?  Looks quite easily accessible to me...  Just get the current document from the Application object, and the rest of the code would be the VBA-equivalents to your post...

And for what it's worth, you can get modelspace (what you called blk in your code) directly from the active document:
Code: [Select]

(setq ms (vla-get-modelSpace *doc*))
(if (= :vlax-true (vla-get-hasExtensionDictionary ms))
   ...
)

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Edit draworder with vba
« Reply #5 on: August 21, 2004, 11:15:40 PM »
Quote from: sinc
Why isn't that available in VBA?  Looks quite easily accessible to me...  Just get the current document from the Application object, and the rest of the code would be the VBA-equivalents to your post...

And for what it's worth, you can get modelspace (what you called blk in your code) directly from the active document:
[

I know I could get the MS direct, but if you want to find the draworder for any layout, you need the block associated with that layout......
What is the VBA equivalent to (entget) that will return the DXF codes? If you look at the Object returned With the dict.item(0), there is nothing associated with it...... :?

jura

  • Guest
Edit draworder with vba
« Reply #6 on: August 23, 2004, 03:48:06 AM »
Thought this was easy.

CADwoman

  • Guest
Re: Edit draworder with vba
« Reply #7 on: December 21, 2005, 09:06:31 PM »
Jeff, I've been trying to write a VB app to control draw order by layer. Looks like this is the right discussion topic. It looks like it's easier to do in LISP but I can't get it to write back to the drawing so that next time I run the routine, it would recall the last draw order. But again, I'm not a VB expert. Did anyone has any success with this?   

Quote from: jura
That's a fine solution for setting the draworder. Thx

The draworder however must be stored in a value somewhere. Is it possible to catch this value to store it in a variabel.
From the DXF reference on SORTENTSTABLE:
Quote
If the SORTENTS Regen flag (bit-code value 16) is set, AutoCAD regenerates entities in ascending handle order. When the DRAWORDER command is used, a SORTENTSTABLE object is attached to the *Model_Space or *Paper_Space block's extension dictionary under the name ACAD_SORTENTS. The SORTENTSTABLE object related to this dictionary associates a different handle with each entity which redefines the order that the entities are regenerated.
It appears that the data saved in this table is NOT accessible with VBA/ActiveX. It IS available to Lisp:
Code: [Select]
(setq layouts (vla-get-layouts *doc*))
(setq ms (vla-item layouts "Model"))
(setq blk (vla-get-block ms))
(if (= :vlax-true (vla-get-hasextensiondictionary blk))
  (progn
    (setq dict (vla-getextensiondictionary blk))
    (setq item (vla-item dict 0))
    (setq ename (vlax-vla-object->ename item))
    (entget ename)
    )
  )
HTH

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Edit draworder with vba
« Reply #8 on: December 22, 2005, 12:35:25 AM »
Hi CADwoman,
You don't say what version you are using. Starting with 2004 or 2005 the SortentsTable was placed into the Acad API. All of my experience in the previous discussion was based on 2002. If you have a newer version, I'd start by looking at the ActiveX Developer help for SortentsTable.

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: Edit draworder with vba
« Reply #9 on: December 22, 2005, 02:30:18 AM »
I've written a solution in Vlisp, should be possible to translate that into VBA:
Visit my homepage -> Free Stuff and search for 'VxSetDrawOrder'
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

CADwoman

  • Guest
Re: Edit draworder with vba
« Reply #10 on: January 13, 2006, 02:25:28 PM »
I am using ACAD2006. The SortentsTable sound like a good place to start. Since I'm not good with VB, it'll take me a while.

Hi CADwoman,
You don't say what version you are using. Starting with 2004 or 2005 the SortentsTable was placed into the Acad API. All of my experience in the previous discussion was based on 2002. If you have a newer version, I'd start by looking at the ActiveX Developer help for SortentsTable.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Edit draworder with vba
« Reply #11 on: January 13, 2006, 03:22:22 PM »
In VBA, could you not get all layers, sort that by number or alphabetically, and use draworder on that list?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)