.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Open DXF and add Text using external application with AutoCAD

8 REPLIES 8
Reply
Message 1 of 9
Raider_71
2944 Views, 8 Replies

Open DXF and add Text using external application with AutoCAD

Hi I have been doing a bit of programming with Visul Studio 2010 (VB) with Inventor and created a number of small standalone applications doing tasks like printing drawings and exporting properties etc.

I am now busy with writing a program exporting all the flat patterns of all the sheet metal parts in an Inventor assembly. I got it right and it works pretty well but now need to add some text to the DXF file. I want to add things like QTY, Thickness and Material to the file. I turned to google and started searching the web just to find that there are a load of nice DXF modules available at a huge cost. Not worth it for a small once off application like this. Anyway then I though that maybe AutoCAD has something I can use as AutoCAD can be available on the PC I will be running the app from.

So does anyone know if this would be possible using VB.net with AutoCAD API with a standalone application, to open a DWG or DXF file created by Inventor and to add a few lines of text and to save it again?

 

Thanks!

 

Pieter

8 REPLIES 8
Message 2 of 9
SENL1362
in reply to: Raider_71

You can do this with and without AutoCAD. Search this forum for samples loading DXF from within AutoCAD.

You could do this without AutoCAD as well because ths DXF structure is still easy to decode.

Open a new AutoCAD drawing, Add one line of text, saveas DXF.

Open the DXF file using Notepad, search for ENTITIES. The lines between  0 up to the next 0 describes the text entity.

Insert this block in youre inventor dxf file, and change de line after 10 with the new X coordinate, after 20 with the new Y coordinate and after 1 with the new stringdata

 

SECTION
  2
ENTITIES
  0                          <---- start of (MTEXT) entity
MTEXT
  5
21F
330
1F
100
AcDbEntity
  8
0
100
AcDbMText
 10                          <---- X-coordinate
100.0
 20                          <---- Y coordinate
150.0
 30
0.0
 40
2.5
 41
0.0
 46
0.0
 71
     1
 72
     5
  1
Hello world                <stringdata
 73
     1
 44
1.0
  0                               <-- start of next entity
ENDSEC

 

 

 

 

Message 3 of 9
Raider_71
in reply to: SENL1362

Thank you for the help. I will follow the manual way. it looks easier.

 

Pieter

Message 4 of 9
jdchakes
in reply to: SENL1362

Hey I am trying to do something similar but am getting issues with the finished dxf.

I get invlaid or incomplete dxf when trying to open in Acad.

I have been trying to get my head around the dxf group codes and how they work with no success.

 

At the moment my code deletes the last three lines of the dxf file:

ENDSEC

0

EOF

 

then adds my text entity:

 

'String to insert at the end of the text file
sText = "  0" & vbNewLine
sText = sText & "TEXT" & vbNewLine  'text entity
sText = sText & " 11" & vbNewLine    'group code -x location
sText = sText & cX & vbNewLine      'x location
sText = sText & " 21" & vbNewLine    'group code - y location
sText = sText & cY & vbNewLine      'y location
sText = sText & " 40" & vbNewLine    'group code -text height
sText = sText & " 30" & vbNewLine    'text size
sText = sText & " 72" & vbNewLine    'group code -horizontal text justification
sText = sText & "  1" & vbNewLine     'centred text
sText = sText & "  1" & vbNewLine     'group code - string itself
sText = sText & oPartNumberValue & vbNewLine 'part number
sText = sText & "ENDSEC" & vbNewLine
sText = sText & "  0" & vbNewLine
sText = sText & "EOF" & vbNewLine

    objFile.WriteLine sText
objFile.Close

 

 

Any help would be awsome!! 

cheers

Message 5 of 9
SENL1362
in reply to: jdchakes

Dxf lines comes in pairs of two, first line an integer, second line data depending, which type depent on the value of the first line.

you remove 3 lines, therefore let the first line of the SECTION pair in the file, i.e.

 

SECTION     2e line

0               1e line

EOF            2e line

 

So you should remove one more line, then insert you're TEXT object.

Then at the end insert the FOUR lines again:

0

SECTION

0

EOF

 

Then i think the pairs for the code 72is not correct.

 

Lastely you can insert the TEXT object in the ENTITIES section (and Block sections) but not in other sections. modern versions of DXF files are more complicated and their last section is probably not ENTITIES and thus inserting TEXT just before the last 4 sections may not be correct.

 

 

 

 

Message 6 of 9
jdchakes
in reply to: SENL1362

Cheers for the reply. In terms of version of DXF, I can export from inventor in 2010,2007,2004,2000 or R12.

I dont think it matters for my nesting software which DXF format I use, is one of these easiest/prefered that you know of?

I will try now with 2000 as this seems oldest and hopefully most simple.

 

I am looking at a list of group codes on the autodesk website,

http://www.autodesk.com/techpubs/autocad/acadr14/dxf/text_al_u05_c.htm

It states group code 72 is for horizonal text justification.

Do these group codes change with different DXF versions?

 

Thanks

Message 7 of 9
SENL1362
in reply to: jdchakes

The most early version, R12 will do for simple drawings.
After more detailed look the 72 code appears to be ok, and normally codes don't change.
Good luck.
Message 8 of 9
jdchakes
in reply to: SENL1362

I think I have found the problem there are some group codes that are NOT optional that i was ommiting such as layer etc.

Once I add these and use R12 format it works perfectly!!

 

thanks 🙂

Message 9 of 9
SENL1362
in reply to: jdchakes

also be aware of empty textstrings

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost