TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: danny on May 04, 2005, 07:59:56 PM
-
need some help or direction
trying to find a way to get the path of a selected xref?
thanks...
-
Have a look at this fine piece of work by MP.
http://www.theswamp.org/phpBB2/viewtopic.php?t=3816
-
Thanks Mark, MP
I'll take a look at it.
-
Not sure what you are looking for, but keep Reference manager in mind. It has some kewl things and also lets you move path's of referenced items.
for 2k2 it is in the extensions, for 2k4 and above it is installed with the program.
Pieter
-
Mark/MP or anyone else,
I've taken a look at MP's function and I'm trying to disect it to find exactly what I need, but all I've gotten so far is a headache.
What I'm trying to do is create a lisp that will open a selected xref file. In order to do that i have to get its path. File size, Flags, or Count is not needed.
I do use refedit, but in some cases an actual opening of the file is neccessary.
-
Have you tried the XOPEN (http://www.integr-8.com/besidethecursor/2005/01/xopen-makes-quickwork-of-external.html)command?
-
(defun *ssnames* (selection_set / num lst)
(repeat (setq num (sslength selection_set))
(setq num (1- num)
lst (cons (ssname selection_set num) lst)
)
)
lst
)
(defun *dxf* (gcode elist)
(cdr (assoc gcode elist))
)
(defun remove2 (ss)
(vl-remove-if-not
'(lambda (x)
(= (logand (*dxf* 70
(entget
(tblobjname "block" (*dxf* 2 (entget x)))
)
)
4
)
4
)
)
ss
)
)
(defun c:xref_tools (str / sel len obj path pos name ent)
(setq sel (ssget '((0 . "INSERT"))))
(if sel
(and (setq sel (*ssnames* sel))
(setq sel (remove2 sel))
(foreach ent sel
(setq ent (entget (tblobjname "block" (*dxf* 2 (entget ent)))))
(setq path (*dxf* 1 ent))
(cond ((eq str "open")
(command "vbastmt"
(strcat "AcadApplication.Documents.Open \""
path
"\""
)
)
)
(T
(setq pos (vl-string-position 92 path nil T)
name (substr path (+ 2 pos))
pos (vl-string-position 46 name 0)
name (substr name 1 pos)
)
(command "_xref" str name)
)
)
)
)
)
(princ)
)
Put all this in the same file. Load it.
Usage:
(c:xref_tools "open") ---> Opens the selected xrefs.
(c:xref_tools "reload") ---> Reloads the selected xrefs.
(c:xref_tools "detach") ---> Detaches the selected xrefs.
**disclaimer** --> These were written and tested for AutoCAD 2000.
Hope this helps,
-
Mark/MP or anyone else,
I've taken a look at MP's function and I'm trying to disect it to find exactly what I need, but all I've gotten so far is a headache.
What I'm trying to do is create a lisp that will open a selected xref file. In order to do that i have to get its path. File size, Flags, or Count is not needed.
I do use refedit, but in some cases an actual opening of the file is neccessary.
Disect it?
Maybe you can better define what mean "The path of a selected xref". How are you selecting it?
But to push forward with an attempt to help (as questionable as that may be before my first coffee) ...
If you load up my utility you might call / invoke it like this:
(GetXrefsProperties
(vla-get-activedocument
(vlax-get-acad-object)
)
)
It might return the following data --
( ( "Taisei Detail Plan"
"C:\\ACAD2006\\SAMPLE\\TAISEI DETAIL PLAN.DWG"
44
1
)
( "Taisei Door Window Sheet"
"C:\\ACAD2006\\SAMPLE\\TAISEI DOOR WINDOW SHEET.DWG"
44
1
)
( "Taisei Interior Elv"
"C:\\ACAD2006\\SAMPLE\\TAISEI INTERIOR ELV.DWG"
44
1
)
)
There are 3 items in the list. Each Item is also a list itself. The first item is the xref name, the second the path, the third the flags* values, and finally the forth is the tally of the number of instances of said xref (normally 1).
So, let's say I "picked" the xref "Taisei Detail Plan" and I wanted the path for it:
(cadr
(assoc
"Taisei Detail Plan"
(GetXrefsProperties
(vla-get-activedocument
(vlax-get-acad-object)
)
)
)
)
=> "C:\\ACAD2006\\SAMPLE\\TAISEI DETAIL PLAN.DWG"
Hope this helps.
:)
*Flags is the bitcoded value associated w/dxf group 70, please see the dxf reference.
-
(vlax-get-property (vlax-ename->vla-object (car (entsel "\nSelect XREF: "))) 'Path)
-
Don't have the XOPEN command? That's okay, using the technique in Will's code and the above, here's one that works just fine in AutoCAD 2002 (no error checking)
(defun C:XOPEN (/)
(vl-load-com)
(command "vbastmt"
(strcat "AcadApplication.Documents.Open \""
(vlax-get-property
(vlax-ename->vla-object (car (entsel "Select XREF for Editing: ")))
'Path
)
"\""
)
)
)
-
Ok, Mr. Slow guy here. :roll:
Given this --
(defun GetXrefPath ( ename / object )
(cond
( (and
(eq 'ename (type ename))
(eq "AcDbBlockReference"
(vla-get-objectname
(setq object
(vlax-ename->vla-object
ename
)
)
)
)
(vlax-property-available-p object 'path)
)
(vla-get-path object)
)
)
)
Try this --
(defun c:XOpen ( / path )
(if (setq path (GetXrefPath (car (entsel))))
(if (zerop (getvar "sdi"))
(vla-open
(vla-get-documents (vlax-get-acad-object))
path
)
(vla-sendcommand
(vla-get-activedocument (vlax-get-acad-object))
(strcat ".open " path "\n")
)
)
)
(princ)
)
Cheers.
:)
-
:P
-
sorry guys,
I think you all wake up a lot earlier than me..
Have you tried the XOPEN command
no, I didn't know that was available. :oops:
(GetXrefsProperties
(vla-get-activedocument
(vlax-get-acad-object)
)
)
This was what a was trying to work with and I can see now, from your routines, how it works.
Thanks for helping me understand.
Hopefully I can krank this stuff out by myself one day...
-
Our pleasure, come back when you're plate empties.
:)
-
o.k, my plates empty...or should I say full, I just don't know how to use my utensils to eat.
I was using the xopen to rename some bad filenames but completing the task at hand has become quite a burden.. I have 150 sheets and I need to find out what xrefs are in the sheets, and rename them. I've been looking around and found a clip from Smadsen.http://www.theswamp.org/phpBB2/viewtopic.php?t=3083&highlight=xref
got some really long file names that need to be simplified. I would post some of them but I'm at home right now. But their way past 30 characters long and its driving me insane. I know I can change the path using reference manager, but the name?
-
Slowly double click the name whilest in xref manager it, will let you edit the name.
Alternatively, one could come up with some kind of scheme to do it automagically, even something simple like xref01, xref02 ... xref30 has to be better than --
IMP-DrawingSheet-yada-yada-yada (http://www.theswamp.org/phpBB2/viewtopic.php?p=63269#63269)-PLANDETAIL(BLDGCESCALATORUP-LEVEL1TO2).dwg
But what I suggest is that you create a little lookup table. For every one of these xrefs with the masochist designed file name, create an alias -- the alias will be used as the xref name in parent drawings. Once you finish the lookup table we could write a simple little function to cycle thru the document's, doing a search and replace on the names.
-
So a table that has
Long a$$ name = name
Lnog a$$ name = name
Long a$$ name = name
I'll work on it..
-
okay,
I made a list of the drawing, sheets and xrefs. The previous designer on this project used Revit. I beleive Revit isn't to friendly after exporting info to dwg. I've got xref files that don't have anything in it but a couple of lines, but yet the sheet that its xrefed in is showing an intire floor plan comming from this file. All layers on, thawed, but only two lines in the xref dwg. Some wierd things going on. I thinking I gonna have to bind everthing to the sheets then create xref files from there. Any Ideas?
If you want to take a look, the excel sheet of file names is in the lilly pond under \danny.
-
I don't have excel installed here yet, any chance you can export to a csv (comma separated values) file? Thanks.
-
done..
-
looking at the list I can see that revit exploded everthing into its own files. Example, Building A Floor 1 has 7 xrefs of the site. Where as it should be 1 xref. Building B Floor 1, Same site, has 6 xrefs of the site, and their all their own files. Should be 1. :shock:
-
Danny, why did you provide aliases for some drawings and not others? Also, the data is inconsistant: sometimes the full path and the alias is separated by one comma, other times 2. Makes it more onerous for a program to process than is necessary.
-
Danny, why did you provide aliases for some drawings and not others?
I've located what sheets the xrefs belong to. As far as renaming them, I am now finding out that they are all bits and pieces of an overall. So lets say sheet AA-101 has these xrefs in themIMP-DrawingSheet-AA-101-BUILDINGALEVEL1FLOORPLAN-FloorPlan-A-1.dwg
IMP-DrawingSheet-AA-101-BUILDINGALEVEL1FLOORPLAN-IMPSiteandStream.rvt-1.dwg
IMP-DrawingSheet-AA-101-BUILDINGALEVEL1FLOORPLAN-PrincessKaiulani.rvt-1.dwg
the xrefs that has the "IMPSiteandStream" is pieces of the IMP-DrawingSheet-AS-101-OVERALLARCHITECTURALSITEPLAN-IMPSiteandStream.rvt-1.dwg
. An xref that is in sheet AS-101.
Also, the data is inconsistant: sometimes the full path and the alias is separated by one comma, other times 2
The full path came from Revit. Makes it more onerous for a program to process than is necessary
I'm realizing this. Your help with the xopen and finding xref paths and info has been very helpful. At this point, I may have to go into every sheet to put together this puzzle. What makes things worse, the base points of all the xrefs are inconsistant as well. :x
Thanks for your help MP, I really do appreciate it.