Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Require Xref, Bind & Explode Routine

20 REPLIES 20
Reply
Message 1 of 21
Anonymous
5351 Views, 20 Replies

Require Xref, Bind & Explode Routine

I have perused the various web site and have not found this routine. What I need is a routine that gathers the Xrefs in a file, binds them and explodes the block. A purge all at the end of the routine would be nice, but the first part is most important. Once created, I'm sure others will make use of this routine.
20 REPLIES 20
Message 2 of 21
Anonymous
in reply to: Anonymous

This should do it....

(if (setq SS (ssget "X" '((0 . "INSERT"))))(progn
(setq CNT 0)
(repeat (sslength SS)
(setq EN (ssname SS CNT))
(setq BN (cdr(assoc 2 (entget EN))))
(if (setq BR (tblsearch "block" BN)) (progn
(if (setq BP (cdr (assoc 1 BR))) (progn
(command "_.-XREF" "B" (vl-filename-base BP))
(command "_.EXPLODE" "L")
))
))
(setq CNT (1+ CNT))
)
(command "_.-PURGE" "A" "" "N")
))
Message 3 of 21
Anonymous
in reply to: Anonymous

That was fast! Thanks for the attention. Your routine did work somewhat. It did bind Xrefs and perform the purge, but it exploded the last block entity added to the file not the bound Xref block just processed. All of the bound Xref blocks are still in place unexploded.

To test your routine I have new file that I inserted a couple of block, then attached three Xrefs, inserted another block and added a dimension after running your routine, the Xrefs did bind, the drawing purged, but the last block type entity inserted, the dimension was exploded. My guess is that your routine locates the last block entity in the drawing database and explodes it, not the bound Xref blocks.

Can you modify the routine to process all and only the Xrefs in the file? Message was edited by: Brockster
I did a few more test of your routine, hence the edit.
Message 4 of 21
Anonymous
in reply to: Anonymous

Here is a more complete routine with comments. I changed the PURGE to only do the Bound-Exploded blocks.

I haven't tested this on nested xref's so that may fail. If you want to test for nesting I can fix that if you need it.
Message 5 of 21
Anonymous
in reply to: Anonymous

That worked just fine! Thank you very much. I owe you a beer the next time your on the east coast, USA.

***************************************
I decided I do want to purge the entire file. I just made the modification to the routine. Message was edited by: Brockster
Message 6 of 21
Anonymous
in reply to: Anonymous

There is a new wrinkle in the process this week. I need the routine to bind using the -ExportToAutoCAD instead of regular Xref bind. I can run this in a script of this just fine, but I still have the problem of exploding the blocks. Is there a way to add what my script is doing into your lisp routine?

.-ExportToAutoCAD
F
2004
B
Yes
T
Bind
prefix
Bound-
;
;

Or, maybe you could write the -ExportToAutoCAD as part of your routine? Here is an example of what one would see at a Command prompt:

Command: -ExportToAutoCAD
File format: 2004
Bind xrefs: Yes
Bind type: Bind
Filename prefix: Bound-
Filename suffix:
Export options [Format/Bind/bind Type/Prefix/Suffix/?] :

I also need to make the layer A-Wall-Patt, color 9 and change all hatch patterns to this layer.

Message was edited by: Brockster
Message 7 of 21
Anonymous
in reply to: Anonymous

Is this what's needed.
If I use the "-ExportToAutoCAD" with the "Prefix" option I will be binding to a new drawing. Then I will need to open that drawing and assume that all top level blocks are bound XRef's and explode them. Then get all hatch patterns and move them to your specified layer. Correct
What version of AutoCAD are you using AEC2006?
Message 8 of 21
Anonymous
in reply to: Anonymous

You raise a good point about new drawing situation.

Let me explain what's going on. The drawings are using Xref's in ADT 2005. We need to send the outside engineers bound files, exploded, without any AEC entities (doors and wall). Unfortunately, the walls contain a hatch pattern that engineers need turned off. The walls and hatch are on the same layer in the wall style. The project is too far along to go back and redefine the wall style in order to get the hatch on a different layer. Your routine helpful as it is, does not address the AEC entities and separation of the hatch patterns. ExportToAutoCAD does bind the Xref’s and remove the AEC entities, but it does leave the problem of running routines on two separate file and dealing with the hatch patterns, which isn’t efficient. I there were just some way to combine the two processes.

Here’s a thought. As the drawing opens via a routine, it could first change the display representation to “Medium Detail”, which turns the wall hatch off. Then use AECOBJEXPLODE. Nope, can’t use that. It exploded all of the walls to layer “0” and that’s a whole different problem. It was suggested I try eTransmit, but that pretty much the same as Xbind and nothing more.

So, that’s it in a nut shell. I’m open to suggestions you or anyone else can come up with.

Thanks in advance…
Message 9 of 21
Anonymous
in reply to: Anonymous

I've thought about this on the drive home and haven't come up with a better idea.

I can use the routine you've provided and add a ExportToAutoCAD at the end. Then, run a second process the new files. So, I need a ssget routine to gather and move the hatch patterns to layer A-Wall-Patt. If there has to be a two step process, so be it.
Message 10 of 21
Anonymous
in reply to: Anonymous

For some reason when I used "-ExportToAutoCAD" in a lsp the program always stopped executing after that command. So I tried the export with a script which works out better since we have to manipulate 2 drawings. I think you will like this.....

Open a new, or any drawing, does not have to be one for exporting but can be. Load "Xref-Export2Acad.lsp". You will get a file dialog to select a drawing, current is the default. The program will write a script to Open the selection, do the export, Close the drawing, Open the "Bound-" drawing, load "xBrockster-Explode.lsp", explode the blocks, create your hatch layer, move the hatches and Close that drawing.

Put both files in the AutoCAD search path and load the Export one. The program will do the rest. Let me know how it turns out.
Message 11 of 21
Anonymous
in reply to: Anonymous

Thank you Lou. I'll do my best to go in a take your routine out for a test drive.

Brock
Message 12 of 21
Anonymous
in reply to: Anonymous

I just test drove your routine and have a few questions.

Does this routine only work on one file or can it be used in a batch program?

Should I only run the Xref-Export2Acad.lsp or should I run xBrockster-Explode.lsp after running Xref-Export2Acad.lsp?

When I xBrockster-Explode.lsp on the newly bound file,every block in the file is exploded including door number, room number, detail callout blocks. These block are comprised of attribute, so exploding these blocks is a big no-no.
Message 13 of 21
Anonymous
in reply to: Anonymous

Only Run the Xref-Export2Acad.lsp. The script loads and executes the xBrockster-Explode.lsp automatically. If you run it again on the "Bound-" dwg it will do the additional exploding you don't want.

Run the Xref-Export2Acad.lsp on a dwg, then open its newly created "Bound-" counterpart and see if the xref blocks are exploded and the hatches are on the correct layer.

If you want the script to not close the "Bound-" dwg open the Xref-Export2Acad.lsp and put a semi-colon in front of line 23.
; (write-line "CLOSE N" FH)

I will see if I can alter this to a batching program without too much work.
Message 14 of 21
Anonymous
in reply to: Anonymous

I haven't said so but thank you for all your efforts.

Now, here's what's happening. If I start off with no particular drawing open and load the routine, I get a dialog box asking me to select a drawing to export to AutoCAD. Once I pick a drawing, I get an error dialog box, see attachment. When I click OK, I'm back in a Select File dialog box. The file I had previously selected is highlighted, so I click OK, the file opens and the process stops. Nothing else happens.

Starting all over, I open the file I want converted and start the routine. I get a dialog box asking me to select a drawing to export to AutoCAD. The same file I have open is highlighted. I click OK and the routine runs, processes the current open drawing file and then I get the error dialog box in the attachment. When I click OK, I’m back in the Select File dialog box. If I click the Bound- file, the file opens to a command prompt. The Xref’s have been bound in the file, but the blocks are not exploded.

Did I miss a step here somewhere?

Brock
Message 15 of 21
Anonymous
in reply to: Anonymous

Obviously our environments and products are different. The only things I noticed are these. The dialog is the standard lisp "Getfiled" routine. It should return a valid path unless you accepted a non-saved dwg like the default "Drawing1.dwg". I did see the attached lisp (fixed) was somtimes failing on comparing the file choice wether it was the current dwg or not because of a text case mismatch. If you are getting a new "Bound-" drawing then the script is running. Is the "explode" lisp somewhere in the AutoCAD search path? Maybe AutoCAD is not finding it? Try again with the attached file.
Message 16 of 21
Anonymous
in reply to: Anonymous

Something is wrong with this line of your routine.
(write-line (strcat (vl-filename-directory (getvar "DWGPREFIX")) "Bound-" (vl-filename-base (getvar "DWGNAME"))) FH)

When the routine runs, this line of text appears in the script:
C:\Program Files\Autodesk Architectural Desktop 2006\Sample\ADT Sample Project\Views\Architectural\Floor PlansBound-03 Fire Rating Plan

There should be a backslash between Floor Plans and Bound-03.
Message 17 of 21
Anonymous
in reply to: Anonymous

You have the answer. All you needed to do is edit the line as shown below. Throw in a backslask before the "Bound".
Lisp requires a double backslash "\\" in a string that will translate to single backslash in a path. Attached is the corrected file.

(write-line (strcat (vl-filename-directory (getvar "DWGPREFIX")) "\\Bound-" (vl-filename-base (getvar "DWGNAME"))) FH)
Message 18 of 21
Anonymous
in reply to: Anonymous

I tried editing the lisp routine using Visual Lisp editor. I added the "\", but when it turned black I knew something was wrong. So I needed to add "\\" instead. I'll give it a shot later today.

Do you think the routine can be made to run in a batch program?
Message 19 of 21
Anonymous
in reply to: Anonymous

Enclosed is the adjusted routine that creates a simple batch. It uses the Multiple File Dialog routine from McNeel's DosLib function library. Included are the Libraries for AotoCAD 2000-2008. Put them all in your AutoCAD search path. I did not test the batch part. Let me know how it works.
Message 20 of 21
Anonymous
in reply to: Anonymous

Wow, this looks interesting. I'll give it a try after this morning meeting and inform you of the results.

Thanks again for your attention on this.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report