Import or run sub from other dvb

Import or run sub from other dvb

stefanveurink68AXD
Advocate Advocate
2,799 Views
8 Replies
Message 1 of 9

Import or run sub from other dvb

stefanveurink68AXD
Advocate
Advocate

Fellas,

 

My problem is the following. There are lots of macro's, or more specific .dvb files. They all need to execute a sub when executed. However, this sub might slightly change in the future. 

 

What I could do is open each file, put the sub in there, and call it. However, when changing in the future, I'll have to change it everywhere. 

 

What I want to do is just refer to the specific .dvb file where the sub is in, and call that sub in that .dvb from all the other .dvb files i've got, hopefully with just a few lines of code. So when changes are applied, all .dvb files are automatically updated. 

 

Is this possible?

 

Thank u anyways. 

0 Likes
Accepted solutions (3)
2,800 Views
8 Replies
Replies (8)
Message 2 of 9

Ed__Jobe
Mentor
Mentor
Accepted solution

Sure this is possible. Just store it in a a location that is in your Trusted Folders and reference the project from the Tools>References menu. Then call the macro using the format Project.Module.Macro. Let's say you have a dvb with a Project call Utilities and a module called Files and a macro called GetFile. You would refer to it using Utilties.Files.GetFile().

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 3 of 9

norman.yuan
Mentor
Mentor
Accepted solution

Yes, it is possible: you organize some of you most common used classes/modules that do the common work and can be shared by other projects in one *.dvb project; then, in other projects, you simply add reference to this *.dvb file (by going to menu "Tools->References..." and clicking "Browse" button to find the shared *.dvb file.

 

This way, if you need to make changes to the shared project, you only do it in one place, assume the change does not break the compatibility (i.e. not class name change, no method signature change).

 

Norman Yuan

Drive CAD With Code

EESignature

Message 4 of 9

stefanveurink68AXD
Advocate
Advocate

Thanks this works great, exactly what I needed. 

 

One more question: how to automatically reference the .dvb? In other words, when I open autocad, I don't want to have to reference the file every time. Seems like this isn't stored in the userprofile (under options), so where do I store this?

 

Thanks!

0 Likes
Message 5 of 9

norman.yuan
Mentor
Mentor
Accepted solution

A VBA project remembers the referenced *.dvb file. That is, you only need to add reference to the shared VBA project once. As long as you save the *.dvb project for any change (including added references).

Norman Yuan

Drive CAD With Code

EESignature

Message 6 of 9

stefanveurink68AXD
Advocate
Advocate

One (or two) more questions about in some way this same issue: 

 

What i've got now is some coordinates in excel. In excel i've written some vba code to export them to autocad as a lwpolyline. 

 

However, I wish to also run a sub (written in autocad, saved as .dvb) from this same routine in excel. First problem i've got with this is it is not possible to reference to a .dvb file in excel. so I can't call the sub (which does all its things in autocad) from excel. 

 

any ideas how to deal with this?

Next to that: at the start i read somewhere on the internet that its necessary to: 

- when data goes from excel to autocad: write your code in excel
- when data goes from autocad to excel: write your code in autocad. 

At the moment i doubt about if this is true since the two programs seem to interact perfectly together, i can get some input from autocad to excel by writing code in excel so... is this really necessary?

 

If answer to second question is no, maybe i can rewrite the excelcode to autocad... which should make it work i guess. 

 

I wonder how you guys think about this. 

0 Likes
Message 7 of 9

Ed__Jobe
Mentor
Mentor

If you're working in AutoCAD, its best to write your code in AutoCAD. You can create an xl object, get the cell contents for the coords and then create your line...and continue working with the line, etc. If you are working from xl, the only option you have is to run the vba macro using the VBARUN command. This will cause the pline creation to not be connected to your process. So in the end, where you put your code, depends on your whole process. Are you working in xl or are you just using it to store points?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 8 of 9

stefanveurink68AXD
Advocate
Advocate

I see, thanks. I've rewritten it to autocad now (quiet quickly) and everything i wanted to work works so I'm satisfied, there wasn't really much hard work in excel to do, copying the points into the worksheet (created by autocad) is enough.  

 

However, I can imagine there might be the same problems when you write something in autocad and you need excel to reference to certain trusted locations (so same problem in other way). seems this can't be done well that's good to know. 

 

Is this same problem also present when working in .net? like with the .net api for autocad like i was once told about here on this forum?

0 Likes
Message 9 of 9

Ed__Jobe
Mentor
Mentor

@stefanveurink68AXD wrote:

Is this same problem also present when working in .net? like with the .net api for autocad like i was once told about here on this forum?


I think with .NET, you're still limited to using COM to work with other apps. So the same considerations apply.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes