Author Topic: Dynamic Xrefs???  (Read 4484 times)

0 Members and 1 Guest are viewing this topic.

SPDCad

  • Bull Frog
  • Posts: 453
Dynamic Xrefs???
« on: September 18, 2008, 03:08:45 PM »
I am brainstorming an idea to compensate for Autocad's lack of dynamic xrefs.

The idea is to create a reactor that retains a DB (dynamic block) path and the file creation date in attributes of a block.
Then a second reactor uses the path to find the block and compares the creation date to the external file date.
If dates are different update block. (basically an xref)

The second reactor I am thinking maybe just a lisp I run on command or on exit to save on computer resources.
Also I had a thought of retaining a list of the blocks to check instead of having autocad check all blocks in the drawing.

Problems encountered so far:

1. Retaining block path
How to retain a blocks path when using the insert command.
I noticed Autocad displays the file path in the dialog box but it does not retain the path.

Possible solutions (PS)
-Write lisp to insert block that retains path.

2. How to save the list of blocks to check?

PS - external file
   
Help is appreciate with both the retaining path issue as well as discussion on the idea.
AutoCAD 2010, w/ OpenDCL

visit: http://reachme.at/spd_designs

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Dynamic Xrefs???
« Reply #1 on: September 19, 2008, 08:46:27 AM »
I think your going to need to write your own suite of tools for this.  As far as keeping track of your dynamic xrefs I think xdata is your friend.  You could also keep your own "collection" aka dictionary, but xdata would be cleaner.  You'll need to write all the normal xref commands: attach, detach, and reload - don't think you'd use unload. 

I see your using OpenDCL so a nice GUI won't be a problem.  8-)
James Buzbee
Windows 8

Daniel J. Ellis

  • Swamp Rat
  • Posts: 811
Re: Dynamic Xrefs???
« Reply #2 on: September 19, 2008, 08:53:01 AM »
How does a dynamic xref differ from a normal xref?
===
dJE

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Dynamic Xrefs???
« Reply #3 on: September 19, 2008, 09:00:20 AM »
It's not really an xref.  It's a dynamic block that you insert, but is referenced to an external source drawing like an xref.  I can actually see something like this used for standards.  The AutoCAD / Architecture standards checkers don't check for blocks.  So if your deep in a project and the project manager wants to change the way a tag looks - or information it contains - your screwed (from a drafting sense).

Hmm.  I may have to look  into this.
James Buzbee
Windows 8

SPDCad

  • Bull Frog
  • Posts: 453
Re: Dynamic Xrefs???
« Reply #4 on: September 19, 2008, 09:30:39 AM »
I rethought the retaining path problem over again came up with xref commands as the way to go.
With XAttach, one can insert the block as an xref and have the path retained. Then one can erase the xref and reinsert the block all in the one command.
I have written a bit of code with the principal in mind and so far there is no need to rewrite the insert command. 

Then I read this morning some else had similar thoughts.

I think your going to need to write your own suite of tools for this.  As far as keeping track of your dynamic xrefs I think xdata is your friend.  You could also keep your own "collection" aka dictionary, but xdata would be cleaner.  You'll need to write all the normal xref commands: attach, detach, and reload - don't think you'd use unload. 

Thanks for the tip on the Xdata or the dictionary. I will explore both.
AutoCAD 2010, w/ OpenDCL

visit: http://reachme.at/spd_designs

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Dynamic Xrefs???
« Reply #5 on: September 19, 2008, 09:52:04 AM »
Here's some xdata stuff to look at.  This will give you the ability to attach name, path and date to the block record - not the inserted block.  This way you can have multiple references.  You can add additional information as necessary. 

Some other thoughts are methods to reload.  Do you go through and delete each Insert, saving graphical data, or do you rename the BlockRef, import the revised block via ObjectDBX, then re-point the Inserts to the new BlockRef?  Dunno.

Xdata Stuff:

Code: [Select]
;;; ;
;;; From AutoCAD's xdata_variants.lsp ;
;;; ;

(defun BuildArrays (DxfTypes dxfValues / ListLength Counter Code VarValue ArrayTypes
    ArrayValues VarTypes VarValues Result
    )
  ;; Get length of the lists
  (setq ListLength (1- (length DxfTypes)))
  ;; Create the safearrays for the dxf group code and value
  (setq ArrayTypes  (vlax-make-safearray vlax-vbInteger (cons 0 ListLength))
ArrayValues (vlax-make-safearray vlax-vbVariant (cons 0 ListLength))
)
  ;; Set the array elements
  (setq Counter 0)
  (while (<= Counter ListLength)
    (setq Code    (nth Counter DxfTypes)
  VarValue (vlax-make-variant (nth Counter DxfValues))
  )
    (vlax-safearray-put-element ArrayTypes Counter Code)
    (vlax-safearray-put-element ArrayValues Counter VarValue)
    (setq counter (1+ counter))
    ) ;_ end of while
  ;; Create the two VARIANTs
  (setq VarTypes  (vlax-make-variant ArrayTypes)
VarValues (vlax-make-variant ArrayValues)
)
  ;; Create a (Lisp) list which contains the two safearrays and
  ;; return this list.
  (setq Result (list VarTypes VarValues))
  Result
  ) ;_ end of defun

;(setq obj(vla-item (vla-get-blocks(vla-get-ActiveDocument(vlax-get-acad-object)))"TAG_SECTION"))
;;; adapted from AutoDesk's function in xdata_variants.lsp ;
;;; use: ;
;;; (kb:putDXrefdata obj "Section Tag" "C:/MyStandardBlocks/Tags" "09.19.2008");
(defun kb:putDXrefdata (obj name path date / obj DxfTypes DxfValues)
  (if (= (vla-get-ObjectName obj) "AcDbBlockTableRecord")
    (progn (setq xdatas (BuildArrays
  '(1001 1000 1000 1000)
  (list "DXref" name path date)
  )
)
   (setq DxfTypes  (nth 0 xdatas)
DxfValues (nth 1 xdatas)
)
   (vla-setXData obj DxfTypes DxfValues)
   )
    )
  (princ)
  )

    ;(kb:getDXrefdataxdata obj)
(defun kb:getDXrefdataxdata (obj / myData key note objtype insScale)
  (setq ename(vlax-vla-object->ename obj)
myData (cadr (assoc -3 (entget ename (list "DXref")))))
  (if myData
    (setq name (cdr (nth 1 myData))
  path (cdr (nth 2 myData))
  date (cdr (nth 3 myData))
  )
    )
  (list name path date)
  )
James Buzbee
Windows 8

SPDCad

  • Bull Frog
  • Posts: 453
Re: Dynamic Xrefs???
« Reply #6 on: September 19, 2008, 10:24:54 AM »
Thanks James for for the Xdata reference and a few other tips.
All your input is appreciated.  You have given me lots of new ideas and problems I never though of.  :ugly:
AutoCAD 2010, w/ OpenDCL

visit: http://reachme.at/spd_designs

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Dynamic Xrefs???
« Reply #7 on: September 19, 2008, 10:43:43 AM »
Your welcome.  I don't post as much help as I'd like - time is very limited (and is going to get even more so).

If I get a chance to work more on this I'll post what I can.  I'd love to see your progress as well!
James Buzbee
Windows 8

Shade

  • Guest
Re: Dynamic Xrefs???
« Reply #8 on: September 22, 2008, 10:26:21 AM »
I was looking into this post and became interested in Dictionaries and Records (D&R).
I found some info at http://www.afralisp.net/ but I would like to learn more.
Where can I find more info and tutorials on D&R.

While playing with making D&R I made a few of each and now I am wondering how do I delete them?

Any help is greatly appreciated.  :mrgreen:

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Dynamic Xrefs???
« Reply #9 on: September 23, 2008, 07:53:12 AM »
AcadX.com had some excellent dictionary resources, but alas the boys have gone.  I'll try to dig through my stuff and see if there is anything of educational value.
James Buzbee
Windows 8

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Dynamic Xrefs???
« Reply #10 on: September 23, 2008, 08:34:13 AM »
OK, I've been working on this a little and I wanted to get the other inmates input on a few things.

Unlike traditional "Design Center" blocks (which are drawings that are inserted and become blocks in the host drawing), Dynamic blocks need to be, well, blocks for the dynamic stuff to exist.  Because of this there are two possible solutions: I have a drawing "MyDynamicToilet.dwg" and there is a block defined in that drawing "MyDynamicToilet" and there exists a reference inserted into model space at the origin. 

Scenario 1: Insert the drawing (command "insert" . . .) and explode entlast.  Now you have the blockref in the active drawing.

Scenario 2: Import the block definition via ObjectDBX and then (command "insert: . . .).

I personally like scenario #2 because unlike #1 only the block definition is being imported - not the whole drawing.  Yes, I know drawings can be fairly well sterilized but I still like the cleanliness of Importing.  Additionally, I have all our standard blocks in one "Block Standards" drawing, so the Import thing would work better there: you wouldn't be tied to one system or the other.

Am I missing anything?  Any other thoughts or concerns?

Thanks.

Oh, a teaser:



James Buzbee
Windows 8

SKUI_BREAKER

  • Guest
Re: Dynamic Xrefs???
« Reply #11 on: September 23, 2008, 10:28:09 AM »
sounds awesome
that would really be awesome if you could do a find a replace  all the old dynamics with the updated block and those blocks that were updated still retianed there visibilities, rotations flips, etc.... oh and attributes most importantly

also i for see a problem of updating the dynamic blocks (ones with attributes that have an action placed on them) because i know sometimes  copy and paste dynamics from one dwg to another and the attributes are usually not in the same place, maybe even backwards or upside down.

i also just came across a new problem where i had place all my annotative dynamic blocks in the dwg.
only to find them all gone the next day as i zoomed extents i saw the block off to the left so, and mirrored them back into place and save the dwg and closed it
then i opened it back up and the blocks were gone again. i asked my self why this was happening for about an hour.
until i realize the scale in properties on the blocks,
they were paste in from another dwg.
and somehow along the way they attained a -z value

x  1.0
y  1.0
z -1.0


so after i mirrored them a again back into place

x  -1.0
y  1.0
z -1.0

i went and changed the scale of X back to 1.0, because in anno blocks it is the only scale number u can change. and that changed all the other axis to 1.0 and that reads

x  1.0
y  1.0
z  1.0


moral of the story updating and copy &pasting annotative dynamic blocks can cause unforeseen problems and must be thoroughly tested.



« Last Edit: September 23, 2008, 10:31:11 AM by SKUI_BREAKER »

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Dynamic Xrefs???
« Reply #12 on: September 23, 2008, 10:52:58 AM »
I don't think any of that will be a problem.  I'm going to use the following:

Iterating through the blocks collection, this will update all block inserts:
Code: [Select]
(setq newblk (subst (cons 2 newName) (assoc 2 entList) entList))
      (entmod newblk)
   

This will sync the attributes:        
Code: [Select]
(if (=(vla-get-HasAttributes obj):vlax-true)
(command "attsync" "select" ent "yes")
)

I know this mixes AutiLISP and ActiveX, but I'v never experienced any problem.
James Buzbee
Windows 8

SPDCad

  • Bull Frog
  • Posts: 453
Re: Dynamic Xrefs???
« Reply #13 on: September 23, 2008, 11:00:34 AM »
A teaser:



Man, you have almost gone completely to town on this haven't you.
Now I am jealous. I have some basic code started but nothing as elaborate as what you have penned.

I am working on more of a reactor type update that will update the blocks on opening or closing of the drawing.  I may have a manual lisp that updates on command too.
 
I am using something similar to Scenario 1, ObjectDBX is over my head for now.

If you wish I can pm the code to you, for a boo.

Thanks for the help, and maybe for the inspiration :ugly: to produce something pretty, not quick and dirty. ;-)
AutoCAD 2010, w/ OpenDCL

visit: http://reachme.at/spd_designs

SPDCad

  • Bull Frog
  • Posts: 453
Re: Dynamic Xrefs???
« Reply #14 on: September 23, 2008, 11:08:00 AM »
Hey jbuzbee you are hijacking my project and I am almost tempted to say stop :x,
but you are taking my original thoughts to new heights and i a very curious to see what you come up with.
Keep up with the good work.

I wish i had more time to devote to this project thou.
Things have picked up at work again, and this little project maybe shelved for a while :(
I hate shelving projects, i usually forget all about them and they never get done!


AutoCAD 2010, w/ OpenDCL

visit: http://reachme.at/spd_designs