ans
July 12, 2016, 6:53am
1
Hello
Let me present my problem:
After an unsuccessful research work, I am asking for your help in order to be able to obtain the coordinates (x,y ) via VBA of the cartridge element of this drawing.
The starting file is a dxf imported via SolidWorks 2012.
Thank you in advance for your answers.
image_1.png
pl
July 12, 2016, 7:26am
2
Hello
What have you managed to do with your macro so far?
Here is a macro that allows you to make a "get" on each of the entities of a drawing, then to make a debug.print of its name:
http://help.solidworks.com/2012/English/api/sldworksapi/Get_All_Visible_Components_in_Drawing_View_Example_VB.htm
Then, when you are positioned on the right element (depending on what the debug.print displays on each line with an IF), you just have to retrieve the position by taking inspiration from the macros proposed here:
https://forum.solidworks.com/thread/60386
1 Like
ans
July 12, 2016, 7:58am
3
Thank you PL for this quick feedback!
To be honest, I tried to use a number of macros on the web but to no avail.
My personal macro is at a standstill due to lack of sufficient knowledge.
When using the two macros you linked, I get the following error messages:
Link Macro 1 :
Error in:
'Get all visible components in the view
vComps = swView.GetVisibleComponents
/sites/default/files/from_ckeditor/macro1.png
Link macro n°2 :
At the level of the 5th line of the macro hand :
Set swSketch = swView.GetSketch
Runtime Error 91 Object variable or With block variable not defined.
/sites/default/files/from_ckeditor/macro2_1.png
/sites/default/files/from_ckeditor/macro2_2.png
Thank you for your help!
pl
July 12, 2016, 8:25am
4
The first link was not good, look this way:
http://help.solidworks.com/2016/English/api/sldworksapi/Get_Title_Block_Tables_Example_VBNET.htm
But what is your level in VBA?
1 Like
ans
July 12, 2016, 8:34am
5
I am proficient in Excel, Powerpoint and Outlook but I am not familiar with Solidworks.
First of all, I have the following instructions in red, so in pirori, incorrect:
Partial class SolidWorksMacro
End Class
When activating the macro, an error message appears in the first line:
Compile error: An incorrect statement outside of a procedure.
pl
July 12, 2016, 8:39am
6
Are we talking about a macro launched from SolidWorks?
If that's the case, you can fire the classes, I think it's useless
1 Like
ans
July 12, 2016, 8:46am
7
Ok that's done however the problem persists at the level of:
SolidWorks imports . Interop.SldWorks
It bugs on the SolidWorks in bold above with the error message:
Compile error: An incorrect statement outside of a procedure.
Any idea about the origin of the problem?
pl
July 12, 2016, 8:47am
8
Can you put your code in a txt file as an attachment on Lynkoa please?
1 Like
pl
July 12, 2016, 9:06am
10
What link did you take from that?
Because I think there is an error in the last line:
Public swApp As SldWorks
It should not be in this place.
1 Like
ans
July 12, 2016, 9:18am
11
I took it from the last link you sent me:
The first link was not good, look this way:
http://help.solidworks.com/2016/English/api/sldworksapi/Get_Title_Block_...
But what is your level in VBA?
remrem
July 12, 2016, 9:20am
12
Your code is not VBA but VB.net.
It can't work...
See you.
1 Like
ans
July 12, 2016, 9:31am
13
That explains a lot of things.
In this case, I'm really at an impasse.
If anyone has an idea, they are welcome.
pl
July 12, 2016, 9:39am
14
Yes the last link is from the VB.NET to modify to adapt it, that's why I asked you for your level.
VB.NET and VBA are two languages that are quite close, but not compatible.
1 Like
remrem
July 12, 2016, 9:46am
15
The example is also available in VBA: http://help.solidworks.com/2016/english/api/sldworksapi/get_title_block_tables_example_vb6.htm
1 Like
pl
July 12, 2016, 9:56am
16
Well, I tried to replace the end of the URL with VB instead of VB6...
ans
July 12, 2016, 10:00am
17
Thank you very much for your help.
I used the vba code given in the link however an error message appears at the level of :
Set feat = tbtAnno.TitleBlockTableFeature
Error Message : Runtime Error 91 Object Variable or With Block Variable Not Defined.
pl
July 12, 2016, 10:14am
18
Two quick questions:
Do you have a background where your cartridge is located or is it in the map directly? Can you select it?
Is it possible for you to select the cartridge with the front mouse or do you want the coordinates without user intervention?
Basically, what's the point?
ans
July 12, 2016, 11:41am
19
The plans are extracted from DXFs made on another software.
There's no background. I can actually select the title block.
The goal is to automatically add an image to the title block on a set of files that do not have a common layout due to their size difference.
As a result, I would like to know how to obtain the coordinates of the title block (or more generally of an element) without user intervention and in the context of a drawing.
Thank you for your help.