Jump to content

XREF in VB


TroutKing

Recommended Posts

Hello again

 

Is there a simple way in VB to attach a user selected XREF to a drawing and then set it to “back”? I would like to create a routine that opens a drawing, then prompts me to negotiate to a folder and select an XREF to attach to that drawing, sets the XREF to “back”, and then moves on to perform the other routines that I am putting into the code.

I believe that this is probably a very simple code but - it doesn’t fall into a category of experience that I have.

Can someone help me with this?

Link to comment
Share on other sites

Holy cow, it would appear that my guess was quite far off. That wasn’t anywhere near as simple as I thought it may be. I’m thinking that since it would require setting up the browser again that this will not work with the previous routine.

 

I was hoping to try and somehow integrate this into the loop routine you helped me with over the last couple weeks which opens a set of drawings and performs a handful of routines on each.

 

I want to set it up so that after the user (me) negotiates to the folder containing all of the drawings to loop through – that I can then pick an xref (that will remain a constant for all the drawings) to be attached to each drawing as they open and run through the loop.

 

Thank you for the code. This will take some head scratching on my part. If you have any other ideas I would love to hear them……….

Link to comment
Share on other sites

I’m not sure that I understand this part of the routine:

 
blkName = InputBox(vbCr & vbCr & "Enter block name for XRef: ", "XRef Image Name")

&

 
Set insertedBlock = ThisDrawing.ModelSpace.AttachExternalReference(PathName, blkName, InsertPoint, 0, 0, 0, 0, False)

What exactly am I defining here? I do not know what to enter or why it is required. An XRef needs a block name? Can you explain?

Link to comment
Share on other sites

Hi again, buddy

Yes, as you can see in Help there is

need to define the block name for XRef

What about your prior question, I think you

need to use ObjectDBX for this batch operation

or use a script

If I'll have a time I'll try to do it later

What the Acad version you have on your machine?

 

~'J'~

Link to comment
Share on other sites

Holy cow, it would appear that my guess was quite far off. That wasn’t anywhere near as simple as I thought it may be. I’m thinking that since it would require setting up the browser again that this will not work with the previous routine.

 

I was hoping to try and somehow integrate this into the loop routine you helped me with over the last couple weeks which opens a set of drawings and performs a handful of routines on each.

 

I want to set it up so that after the user (me) negotiates to the folder containing all of the drawings to loop through – that I can then pick an xref (that will remain a constant for all the drawings) to be attached to each drawing as they open and run through the loop.

 

Thank you for the code. This will take some head scratching on my part. If you have any other ideas I would love to hear them……….

 

Here is very quick and dirty scratch

but seems to be working for me

Give this a try

 

~'J'~

XREF_INSERT.zip

Link to comment
Share on other sites

Hi Oleg :)

 

I was able to incorporate the first code you showed in this thread into my routine and get it working! :shock: However – there are two things that I want to add/change.

 

Let me explain what I’m doing.

My basic watered down example:

 

I have 3 folders (all of which may routinely change).

 

Folder 1 - contains all of the drawings that I want to open (all of these drawings fit together like puzzle pieces if inserted or XRef’d together)

Folder 2 – has one drawing only. This drawing is a composite of all the other drawings (in gray scale)

Folder 3: is empty. This is the folder that my final output drawings will go into.

 

In a loop I am:

- Opening the drawings from Folder 1

- XRefing the drawing from Folder 2 into my open drawing

- Saving the DWG as a DWF into folder 3

 

So far, with all the help I’ve received, this program works. I like it and it works well. It is doing what I need it to.

 

However, there are two additions/changes that I need to make:

1. Currently in this routine I am prompted to pick the drawing that I am XRefing from Folder 2. This is what I want. BUT - I want that XRef’d drawing to remain static AFTER I choose the drawing the first time. Currently the routine is making me choose that XRef for every drawing throughout the loop.:x

2. I want the ability to choose both Folder 1 and Folder 3 at the beginning of this routine. I see that oldguy posted a possible fix to this problem on one of my other threads but I haven’t been able to get that far yet.:cry:

 

Can you help me with problem #1? I believe the fix is fairly simple but I have been unsuccessful in my attempts. Once that problem is fixed – I can move on to problem #2.

 

(I realize that this code may not be as clean and categorized as you guru’s are able to make it – but I’m self taught and there are large gaps in my knowledge and familiarity with VB.

For instance - I do not know the difference between “Public Function, Private Function and Function etc)

Copy of UserDirectedFolderToConvertDWGtoDWF(SafeAsOf_06.06.07.zip

Link to comment
Share on other sites

Hi, buddy

No warranty that I can do it

Anyway I'll try it if I can to translate

your message on my native language

exactly

LOL

 

~'J'~

Link to comment
Share on other sites

Hi again Oleg

 

I just wanted to make sure that you saw the file that I attached. It contained the complete working code for what I am doing. I don't need everything re-written. I think it should just take a minor adjustment to get that XRef path static after the first loop. I have tried - and I believe that I came close - but I didn't quite get it correct.

 

I appreciate all of your efforts!

Link to comment
Share on other sites

It just seems to me that - from the routine - I should be able to take this:

 

 
Dim xrfilename As String
Dim blkname As String
xrfilename = "" ' clean up previous
Dim p, f, s
p = ThisDrawing.GetVariable("DWGPREFIX")
f = "AutoCAD Drawings and Templates|*.dwg;*.dwt|All Files|*.*|"
xrfilename = BrowseForFile(p, f)
blkname = "XREF_IMAGE" '"" 'InputBox(vbCr & vbCr & "Enter block name for XRef: ", "XRef Image Name")

 

And add a simple IF statement such as:

 

 
[b]If xrfilename = "" Then[/b]
Dim xrfilename As String
Dim blkname As String
xrfilename = "" ' clean up previous
Dim p, f, s
p = ThisDrawing.GetVariable("DWGPREFIX")
f = "AutoCAD Drawings and Templates|*.dwg;*.dwt|All Files|*.*|"
xrfilename = BrowseForFile(p, f)
blkname = "XREF_IMAGE" '"" 'InputBox(vbCr & vbCr & "Enter block name for XRef: ", "XRef Image Name")
[b]End If[/b]

But for some reason xrfilename does not retain the original path and drawing so when it goes through the loop the second time I am still prompted to negotiate the path of the XRef. What am I missing?

(this board needs an emoticon of a guy pulling his hair out)

Link to comment
Share on other sites

If xrfilename = "" Then

Dim xrfilename As String

 

Troutking you have to work at it to get these 2 lines in that order.

Option explicit is there to stop this kind of thing.

On error resume next is to help people ignore option explicit and do just this.

The basics are-

1)Dim Something as string (It has no value until you assign it one.)

2)Give it a value.

Link to comment
Share on other sites

Hi Bryco

One of my problems is that I do not have a complete knowledge of how VB is set up - for instance - like understanding exactly what "Option Explicit" means. But I'm learning as I go and I've had some excellent help here.

 

As far as your reference to giving xrfilename string a value:

The portion of the routine that I posted above is just a small piece of the total routine. If you open up the attachment that I supplied above you can see that I do give the xrfilename a value as it progresses through the routine. After I give it the initial value (further down in the code) I would like it to then retain that value throughout the entire routine process. I'm not sure how to keep it at a constant value one it is given one.

Link to comment
Share on other sites

I did it! I did it! I made it work! WOO HOO!!!!!!

 

I just needed to change some of the code placement around and get the code revolving around the xrfilename inside the main loop.

 

I know that you gurus out there would frown seriously on the "cleanliness" of my code - but it works!!!!

 

Now..... on to my last problem with this routine (the one revolving around the user specified output folder)

Link to comment
Share on other sites

Test this module on any file

If this will work for you I could be

to go further to add batch process

Turn back my changes as you need,

folder name etc., see code

Hth

 

~'J'~

modToDWF.zip

Link to comment
Share on other sites

  • 1 year later...
Here is very quick and dirty scratch

but seems to be working for me

Give this a try

 

~'J'~

 

Not sure if this is a dead topic or not but after reviewing and text the code This is exactly the direct I want to go with but with two changes to how it works.

  • This code xrefs into the layout tab where I would want to xref into model space.
  • This code adds a number to the exref where I would just want the name of the xref drawing(minus the '.dwg" as the name with no numbers added to the end.

Since I am learning VBA cod and have very little experience with AutoCAD code could someone take a look at it, make a few changes to adapt what I am looking for the post it back up here?

 

I have roughly 5 projects containing anywhere from 10 to 231 sheets. I really do not want to have my staff open each one individually to xref one drawing. This will save me tons of valuable time!

 

Thanks In Advance

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...