Drawing a dxf cylinder

I have a cylinder in parametric form, that I want to draw as a dxf. What would be the optimal way of doing this with dxflib? Using polygons? NURBS? I am new to AutoCAD and not sure about the ways I can do this. I tried creating a cylinder in AutoCAD 2014 and exporting it to DXF and it only creates two circles, with the base and top part of the cylinder. Also, it looks like it cannot be rotated…

dxflib is mostly suitable for 2D content. We use it for the free community edition of QCAD (also 2D).
3D content might be achievable using extrusion. Please note that not every viewer / CAD system supports these. QCAD being 2D doesn’t.

Thanks a lot for your anwser andrew. So are you saying that dxflib is not capable of achieving what I want or that the result will not be compatible with every viewer? I am OK with the second, I don’t need full compatibility. If indeed would be possible to use extrusion with dxflib, could you point me in the right direction, so I can try to experiment a little bit (what entities I need to use, etc.)?

dxflib does currently not support writing extrusions. Support could be added relatively easily in DL_Writer::entityAttributes.

Note that even if you have extrusion support, you won’t be able to create a cylinder that is rotated in 3D space (extrusions are parallel to the X/Y plane).

I would not mind adding extrusions myself and contributing to the project, but I would need to be able to rotate the resulting primitive. Can this be achieved using dxf?

Not 100% sure, but I think you’d have to use a 3DSOLID entity to represent such a body.
3DSOLID entities are available in DXF but consist of proprietary, binary, undocumented data.

I’d recommend to find a 3D CAD application, create the type of cylinder you need, export it to DXF and cross-check the result with a 3D DXF viewer. The DXF file reveals what entity can be used best to represent such a body.

I have been looking at DXF documentation and in the circle entity I can see:

210

Extrusion direction (optional; default = 0, 0, 1)
DXF: X value; APP: 3D vector

220, 230

DXF: Y and Z values of extrusion direction (optional)

Wouldn’t that let me extrude in any direction I want?

You’d have to try it:
Export a circle to DXF
Add the extrusion vector manually
Load the resulting DXF file in a 3D viewer

Ok, I’ll go ahead and try. I’ll keep you updated with the results. Thanks a lot for your help.

I can confirm it is possible to create a 3D cylinder extruding a circle, using extrusion direction and thickness. The main problem is that when using a extrusion direction different from the default one (0,0,1), the object appears in different coordinates, as if the UCS was changed… Anyone knows why can this be happening? In the upcoming weeks I’ll try to make it work with dxflib, and see what happens…