Anuncios

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Algorithm extracting data from DWG file

Anonymous

Algorithm extracting data from DWG file

Anonymous
No aplicable

I'm a University student and I have a project to program a machine to draw the content from a .DWG file. I really need an algorithm to read the necessary data from a .DWG file. I tried to google it but all I could find was solfwares to convert .DWG file to .PDF file.

If anyone has idea about this topic, please share with me. I'm really grateful. 

0 Me gusta
Responder
3.143 Vistas
14 Respuestas
Respuestas (14)

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> program a machine to draw the content from a .DWG file

Are you referring to a NC/CNC system and you need to convert geometry to be manufactured by such a system?

Or is it more a 3D print workflow you are thinking about?

Do you want to work with 2D or 3D?

 

A bit more information will help to receive valid replies.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2025
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Me gusta

Anonymous
No aplicable

My project is to program a SCARA to draw the content of a .pwg file into A4 size paper. So, it's 2D, and I may ask my professor for more details a few days later, but I think I need the machine to understand .pwg file from AutoCad2015 or later.

Thank you.

0 Me gusta

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> program a SCARA to draw the content of a .pwg file into A4 size paper

I guess you mean ".dwg" file (not ".pwg"), just to make sure we speak about the same file format.

Another question: do you have access to AutoCAD? You'll need that to get access to the geometry.

Next you need to decide which of the API's you want to use from AutoCAD (LISP, VBA, .NET, C++) and at least you need to know which types of objects your dwg-file can contain. As long as there are only 2D-Polylines, then the job is more easy compared to complex geometry like blocks scaled/rotated, some 3D-surfaces (you need to get contours from), ...

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2025
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Me gusta

Anonymous
No aplicable

Yeah, it's .dwg file, my bad. Sorry about it.

I have access to AutoCad. But is it really necessary? Can you explain this detail? Thank you very much.

I'm trying to program using C++ language. The project for now should be just simple 2D-Polylines and text, but it may consist of curves later on, but then it would still be in 2D.

Thank you.

0 Me gusta

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> I have access to AutoCad. But is it really necessary?

You can't access geometry within a DWG-file without software that can open this file.

A DWG-file is not an open source format and so the number of libraries which can read that format is really limited. Using AutoCAD is the most appropriate way.

 

>> Can you explain this detail?

Nothing much to explain, open the file you need to convert to a machine language. Use API to get the objects in modelspace of the DWG and convert each geometry type to your NC codes.

 

>> The project for now should be just simple 2D-Polylines and text,

Text could be tricky as AutoCAD (without additional development) does not have access to the contours of a true-type font. But Polylines (take care: AutoCAD knows 3 types of Polylines, and one polylinetype knows a additional settings like "curved" and "splined", you can test this with AutoCAD command _PEDIT)

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2025
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Me gusta

Anonymous
No aplicable

>> Using AutoCAD is the most appropriate way.

I have AutoCAD to open .DWG file and I also have converter to convert the .DWG file to .PDF file in my PC. But I think the problem is that my professor wants the machine itself to recognize the file. So instead of open a specific file on my PC and convert it to machine language, I think he wants the machine can understand the protocol even if the input is any random .DWG file.

I will ask him about this on Tuesday for further details. But is it possible to write a code to do the task like that?

And can you show me how to use API to get the objects in .DWG file (in this case I would be more comfortable with C++ more than other languages)?

Thank you.

0 Me gusta

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> But I think the problem is that my professor wants the

>> machine itself to recognize the file

That would be a hard job.

I don't know which software/operating system is working on that machine. Creating a DWG-reader means man-years of development (and that repeats with every new dwg-format if Autodesk decides to change the format).

You might look to the >>>Open Design Alliance<<<, but that's not free and I doubt it works on a limited system like a NC-system.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2025
------------------------------------------------------------------------------------

(not an Autodesk consultant)

Anonymous
No aplicable

I forgot to ask in the previous post but can you show me how to use API to get the objects in .DWG file (in this case I would be more comfortable with C++ more than other languages)? 

Thank you.

0 Me gusta

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> can you show me how to use API to get the objects in .DWG file

You might look to the ObjectARX kit, it includes a lot of samples showing how to access content of dwg-files:
>>>ObjectARX<<<

 

You can also find a forum for ObjectARX >>>there<<<

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2025
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Me gusta

Anonymous
No aplicable

Thank you.

0 Me gusta

leeminardi
Mentor
Mentor

You state that as a student you have a “…project to program a machine to draw the content from a .DWG file”. What is the objective of the assignment? For example, is it to give you experience in reading a binary or ascii file to another format? Or perhaps to reformat geometry from one format to another and create the necessary instructions to drive servos that are part of a machine that draws? Or something completely different? Is the course part of a computer science program or mechanical engineering? My guess, and it’s only a guess, is that it is more of an engineering assignment than a computer science task. As such I do not think reformatting a binary .dwg file or even an ascii .dxf is the objective of the assignment. I think the focus may be how to translate 2D polyline-like geometry into instructions to drive an x-y type plotter machine. For this task I think you might consider using the list command in AutoCAD to create data that defines the shape. There is significant challenge in translating this data into a format necessary to drive your machine especially if the geometry includes arcs. For example, here’s sample output from the list command for a polyline with two straight segments followed by an arc that is followed by another straight segment.

Command: LIST
Select objects: 1 found
Select objects:
                  LWPOLYLINE  Layer: "0"
                            Space: Model space
                   Handle = 20a
              Open
    Constant width    0.0000
              area   67.2718
            length   40.8869
          at point  X=  11.2096  Y=   8.5308  Z=   0.0000
          at point  X=  20.1063  Y=  15.4322  Z=   0.0000
          at point  X=  29.3646  Y=  10.4097  Z=   0.0000
             bulge    0.3653
            center  X=  33.2029  Y=  17.4850  Z=   0.0000
            radius    8.0493
       start angle       242
         end angle       322
          at point  X=  39.5271  Y=  12.5054  Z=   0.0000
          at point  X=  47.2303  Y=  13.8423  Z=   0.0000

I think you need to clarify the educational goal of the assignment before continuing.

lee.minardi

Anonymous
No aplicable

The goal of the project is to study of machine programming in the automatic field. The topic is to program a SCARA machine to be able to draw the content of .DWG file. So, as you stated, the project should focus on translating 2D polyline-like geometry into instructions to drive an x-y type plotter machine. But before that I really need to know how to extract the geometry data in a .DWG file.

Can you show me how to get the command list from a random .DWG file? For example if someone gives me a .DWG file. how can I extract such command list?

Thank you.

0 Me gusta

leeminardi
Mentor
Mentor

A .dwg file is a binary file that has a proprietary format controlled by Autodesk.  It's format can change from version to version.  AutoCAD can also save files in a .dxf format.  DXF is an ASCII file that was originally created to enable 3rd party developers to write software that complements the features of AutoCAD. I think it would make much more sense for you to work from a dxf rather than dwg file. 

 

For example, the dxf code for a lwpolyline looks like this.

 

A portion of the code for a dxf file with a polyline with two straight segments followed by an arc then another straight segment looks like this:

AcDbPolyline
 90
        5
 70
     0
 43
0.0
 10
8.319873837667117
 20
11.99992329523352
 10
19.42205923226548
 20
16.98133090859468
 10
31.08996107392547
 20
11.04603673852302
 42
0.4338377669093521
 10
37.80784396922083
 20
13.48374686732284
 10
46.1521615979551
 20
16.16876090508994

A 10 indicates that an x coordinate follows, a 20 signifies a y coordinate.  Arcs are represented by "bulge factor (dxf code 42) where:

bulge = tan(angle/4), CCW is positive

 

You can search the dxf file for AcDbPolyline then extract the data you need to create the instructions to drive the SCARA.

lee.minardi
0 Me gusta

dgorsman
Consultant
Consultant

Would you mind having you instructor join in on the discussion?  What you are describing is a highly advanced task, not something encountered in an average assignment, and certainly not without a deep understanding of DWG content, Object ARX, and RealDWG.  I'd like to make certain that both of you understand the actual task at hand. 

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.