TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: AVCAD on June 13, 2005, 12:06:54 PM

Title: Looking for Xref Routine....
Post by: AVCAD on June 13, 2005, 12:06:54 PM
Is there are routine out there that will do the following:

Detattch an xref in a drawing
Save the where and what rotation it was at
reinsert the xref
and restore th placement of that xref

And if so, Can it do multiple Xrefs in 1 drawing...basically all xrefs.
Title: Looking for Xref Routine....
Post by: Jeff_M on June 13, 2005, 12:16:26 PM
If you are wanting to reset the layers to match that of the Xref drawing, I do have a VBA macro to do that. That is essentially all yoy are doing with the re-inserting of them.
Title: Looking for Xref Routine....
Post by: Dommy2Hotty on June 13, 2005, 12:28:25 PM
Unless I'm missing something, isn't that just reloading the xref?
Title: Looking for Xref Routine....
Post by: daron on June 13, 2005, 12:33:38 PM
Yes, but I can't give mine out.

Check your dxf values and set variables for them
(entget (car (entsel)))
Insertion point 10
Rotation angle 50? I forget.
Of course, Dommy's comment should be the same thing, unless you need these for a greater purpose than you've let on here.
Title: Looking for Xref Routine....
Post by: CADaver on June 13, 2005, 12:42:10 PM
I'm with Dommy on this one.  Why not just unload the files, then reload when you want 'em back.  All the layer controls remain set.

Some quickies:
Code: [Select]

(DEFUN C:xru ()
(command "-xref" "unload" (cdr (assoc 2 (ENTGET (CAR (ENTSEL "\N Select Element in XREF to UNLOAD  "))))))
)  
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(DEFUN C:xrd ()
(command "-xref" "detach" (cdr (assoc 2 (ENTGET (CAR (ENTSEL "\N Select Element in XREF to DETACH  "))))))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(DEFUN C:xre ()
(command "-xref" "reload" (cdr (assoc 2 (ENTGET (CAR (ENTSEL "\N Select Element in XREF to RELOAD  "))))))
)
Title: Looking for Xref Routine....
Post by: AVCAD on June 14, 2005, 02:29:57 PM
Just unloading the Xrefs wont change all the colors, or the Layer state according to t he master xref file.

Jeff may have what I am looking for. He was correct when saying all I want is to change the layer states of the master xref file.

If unloading a drawing that is xrefed already wont shut off the (lets jsut say) Doors layer if I had shut it off in the master xref file. IT will still keep the layer states that are current in that file.

Does that make any sense I think I lost my self.....

I would like to try out the VBA macro that Jeff uses. EMail it to me me or post it here please.
Title: Looking for Xref Routine....
Post by: CADaver on June 14, 2005, 02:32:44 PM
Ahh VISRETAIN.
Title: Looking for Xref Routine....
Post by: Jeff_M on June 14, 2005, 03:20:55 PM
Avcad,
I posted a zip file in The Lilly Pond (http://www.theswamp.org/lilly_pond/jeff_m/Xref_Sync.zip?nossi=1) with my routines. The lisp file will call the correct dvb file depending on the version of Acad you are using (or it is supposed to anyway). To use, make sure all 3 files are in the support search path, just load the lisp and type XREF_SYNC to run it.

Jeff
Title: Looking for Xref Routine....
Post by: AVCAD on June 14, 2005, 05:32:36 PM
I am using ACAD Version 2004

I am getting an error and it is opening Visual Basic to fix it but I have no clue what to fix...

any help would be nice

Thanks!
Title: Looking for Xref Routine....
Post by: Jeff_M on June 14, 2005, 06:35:43 PM
What is the error?
What line is highlighted in the VBAIDE?
Title: Looking for Xref Routine....
Post by: CADaver on June 14, 2005, 08:21:44 PM
Quote from: AVCAD
I am getting an error
You didn't like VISRETAIN?

Code: [Select]

(defun c:fixxrefcolors ()
(command "undo" "begin")
(setq fixedxref  (cdr (assoc 2 (ENTGET (CAR (ENTSEL "\N Select XREF to Reset Layers  "))))))
(command "-xref" "unload" fixedxref)
(setvar "visretain" 0)
(command "-xref" "reload" fixedxref)
(setvar "visretain" 1)
(command "undo" "end")
(princ)
)
(defun c:fxc () (c:fixxrefcolors))
Title: Looking for Xref Routine....
Post by: CADaver on June 14, 2005, 08:31:50 PM
Code: [Select]

(defun c:fixallxrefcolors ()
(command "undo" "begin")
(command "-xref" "unload" "*")
(setvar "visretain" 0)
(command "-xref" "reload" "*")
(setvar "visretain" 1)
(command "undo" "end")
(princ)
)
Title: Looking for Xref Routine....
Post by: AVCAD on June 15, 2005, 09:50:00 AM
when I run the xref_sync command this is the line that is  highlighted...


Dim dbxDoc As AxDbDocument


???? I have no clue what that means.. :?
Title: Looking for Xref Routine....
Post by: AVCAD on June 15, 2005, 09:54:14 AM
I will have to play with that CAD. I never really played with the visretain options.
Title: Looking for Xref Routine....
Post by: MP on June 15, 2005, 09:56:17 AM
It's an ObjectDBX document. You'll need to add a reference to the AutoCAD/ObjectDBX Common Type library thru "Tools -> References" from the VBA editor.
Title: Looking for Xref Routine....
Post by: Jeff_M on June 15, 2005, 12:36:41 PM
The problem with changing VISRETAIN is that it affects ALL Xrefs you have in the drawing. If you only want to update the layers to match those in one Xref and you have 2 or more, VISRETAIN is NOT what you want. That is what led me to write the VBA macro.

AVCAD, sorry about that. I should have noted that since I don't have R2004+ I couldn't set the reference. Once the VBAIDE opens with the error, select the cancel/end button. Still in the VBAIDE, go to the Tools pulldown menu and select References... In the references dialog you will see an item near the top that says ObjectDBX Type 1.0 library(not found)...uncheck the box next to that; scroll down and find another ObjectDBX  X.X Type Library, where X.X is a higher number than 1.0, and select it. Save and close. That should fix it.
Title: Looking for Xref Routine....
Post by: CADaver on June 15, 2005, 01:21:36 PM
Quote from: Jeff_M
The problem with changing VISRETAIN is that it affects ALL Xrefs you have in the drawing.
ummm... not in R2002.  It only affects those you reload while it is off.


Quote from: Jeff_M
If you only want to update the layers to match those in one Xref and you have 2 or more, VISRETAIN is NOT what you want.
Gee, it works just fine for me, but I was making it even harder than it needed to be:

Code: [Select]
(defun c:fxc ()
(command "undo" "begin")
(setvar "visretain" 0)
(command "-xref" "reload" (cdr (assoc 2 (ENTGET (CAR (ENTSEL "\N Select XREF to Reset Layers  "))))))
(setvar "visretain" 1)
(command "undo" "end")
(princ)
)



Now if you want to pick a bunch to reset try this:

Code: [Select]
(defun c:fxc ( / old setlgth co t2 temp blkname)
(command ".undo" "BEGIN")
   (setvar "cmdecho" 0)
   (setvar "visretain" 0)  
   (prompt "\N Select XREFs to Reset Layers  ")
      (setq
        old (ssget)
        setlgth (sslength old)
        co -1
        t2 "t"
      )
  (while (boundp 't2)
     (progn
       (setq
         co (1+ co)
         temp (entget (ssname old co))
         blkname (cdr (assoc 2 temp))
         t2 (ssname old (1+ co))
       )
(command "-xref" "reload" blkname)
       )      ;; end progn
   )          ;; end while
(setq co (1+ co))
(setvar "visretain" 1)
(princ (strcat "\n  FINISHED...  " (rtos co 2 0) " XREFs Reset to original colors"))
(princ)
(command ".undo" "END")
(princ)
)



Quote from: Jeff_M
That is what led me to write the VBA macro.
Now VBA may work faster, but toggling VISRETAIN is working for me.
Title: Looking for Xref Routine....
Post by: Jeff_M on June 15, 2005, 01:53:12 PM
Quote from: CADaver
Quote from: Jeff_M
The problem with changing VISRETAIN is that it affects ALL Xrefs you have in the drawing.
ummm... not in R2002.  It only affects those you reload while it is off.
Quote from: Jeff_M
That is what led me to write the VBA macro.
Now VBA may work faster, but toggling VISRETAIN is working for me.

OK, I'll admit I never tried changing VISRETAIN/unload/reload on individual xrefs. What I originally wanted was a way to update just the linetype or color of the xref layers, not necessarily the entire drawing's display. I guess it was for more of a specific purpose that I have migrated to general use.
Title: Looking for Xref Routine....
Post by: CADaver on June 15, 2005, 02:28:17 PM
Quote from: Jeff_M
What I originally wanted was a way to update just the linetype or color of the xref layers, not necessarily the entire drawing's display.
That's all it does, it only updates the display of the selected XREF, not the entire drawing.  Or am I missing something?

Quote from: Jeff_M
I guess it was for more of a specific purpose that I have migrated to general use.
How much more specific than a selected XREF do you want to get?
Title: Looking for Xref Routine....
Post by: Jeff_M on June 15, 2005, 03:13:46 PM
Quote from: CADaver
That's all it does, it only updates the display of the selected XREF, not the entire drawing.  Or am I missing something?

How much more specific than a selected XREF do you want to get?

The architect changes the linetypes to be used for some features on his plan. I have his drawing Xref'ed into mine with only specific layers thawed & on. To update the new linetypes using VISRETAIN means I must update the entire Xref in my drawing meaning I must go back and freeze/thaw & turn /on/off my specific layers. Using my macro I only update the linetypes.....period.
Title: Looking for Xref Routine....
Post by: CADaver on June 15, 2005, 03:48:15 PM
Quote from: Jeff_M
The architect changes the linetypes to be used for some features on his plan. I have his drawing Xref'ed into mine with only specific layers thawed & on. To update the new linetypes using VISRETAIN means I must update the entire Xref in my drawing meaning I must go back and freeze/thaw & turn /on/off my specific layers. Using my macro I only update the linetypes.....period.
Gee, had I just downloaded your function and run it, I'd have seen that.  That's pretty cool Jeff, the only thing to make that slicker I could see is allowing multiple xref file selections.
Title: Looking for Xref Routine....
Post by: Jeff_M on June 15, 2005, 04:05:45 PM
Quote from: CADaver
That's pretty cool Jeff, the only thing to make that slicker I could see is allowing multiple xref file selections.
Thanks! Yeah, this was actually one of my first VBA applications...and I had no clue how to do that. Now that I know how to at least find a clue, maybe I'll go back and see if I can add the multiple files option.
Title: Looking for Xref Routine....
Post by: CADaver on June 15, 2005, 05:11:54 PM
Quote from: Jeff_M
Quote from: CADaver
That's pretty cool Jeff, the only thing to make that slicker I could see is allowing multiple xref file selections.
Thanks! Yeah, this was actually one of my first VBA applications...and I had no clue how to do that. Now that I know how to at least find a clue, maybe I'll go back and see if I can add the multiple files option.
Yeah well, don't break a neck on my account, I gripe if I was hung with a new rope.
Title: Looking for Xref Routine....
Post by: AVCAD on June 16, 2005, 10:49:43 AM
Jeff,

I am in the same boat you are. I first receive a set of Arch files, clean them up and change the colors to specific color that our ctb file uses, thaw, off, and lock layers that we dont need. Then I xref the arch files to a "master xref" for our office.

Right now everytime I get updated drawings I have go through that process over and over again. If I just over wrote the old drawings with the new drawings and used the visretain option on my sheet files all the xref'ed layers would then take the architects colors and layers settings back.

I still havent gotten your program to work...actually I havent tried to fix it yet  :wink:

we will see what happens.
Title: Looking for Xref Routine....
Post by: AVCAD on June 16, 2005, 10:56:37 AM
Quote from: Jeff_M
AVCAD, sorry about that. I should have noted that since I don't have R2004+ I couldn't set the reference. Once the VBAIDE opens with the error, select the cancel/end button. Still in the VBAIDE, go to the Tools pulldown menu and select References... In the references dialog you will see an item near the top that says ObjectDBX Type 1.0 library(not found)...uncheck the box next to that; scroll down and find another ObjectDBX  X.X Type Library, where X.X is a higher number than 1.0, and select it. Save and close. That should fix it.


OK I tried this but the references option is greyed out?  :?
Title: Looking for Xref Routine....
Post by: Jeff_M on June 16, 2005, 11:49:00 AM
Quote from: AVCAD

OK I tried this but the references option is greyed out?
I think that the references is only greyed out if you try to access it while the program is still running. Make sure to End the macro before editing. You may need to load the dvb manually since the lisp routine is supposed to unload it. To do that, before trying to run it type VBAMAN at the command prompt. In the dialog select "Load" and browse to the Xref_sync-2004.dvb file and load it. Now select the "Visual Basic Editor" button. In the VBAIDE you should have a pane on the left with any open projects, make sure that the Xref_sync is the one highlighted then set the references correctly and save.

If this doesn't work, maybe someone else with experience and 2004 can fix it up for you.