Export DXF to Structure File (xtp) #Parameter #structure


Russell Shilling
 

I've recently installed XTrackCAD after using a much earlier version. It is greatly improved over the version 4.x I last used. One thing still lacking is the ability to easily create structures. I'm a little spoiled as I use LibreCAD for drawing plans, which is both free (Libre) and very useful. So I set about creating a DXF to XTP exporter.

Right now it is written in C# for Windows, but there is nothing magical about it - it reads and writes lines from and to files. It should be easyish to port to C or C++ and make it cross-platform capable. It needs work to be useful to the average user. How many XTC users would be interested in this?

XTrackCAD layout with Rico Water TankLibreCAD drawing of Rico Water Tank


Joost van der Waa
 

That would be a very nice tool !!!
I have been adding structures myself and it was a very tedious job with lots of errors before I was satisfied with the result, mainly because you are working in coordinates alone and have to do everything in inches where I am on the metric part of the planet.

Please don't count the enthusiasm on reactions in this group alone, there are many more XTrackCad user out there....

Joost


jklaas@...
 

As I primarily use Linux and my C is is rustier than an old nail in the ocean, I'm not sure how much help I would be in porting it, but I would love to see something like this.


Neil
 

Joost - Yep metric would be good! I am also old enough to remember and understand Imperial, as I am in the UK, but purchased items are now usually defined in mm.

 

A cad design tool import interface would be good and would save dividing mm measurements by exactly 25.3999 or close approximation 25.4 or multiply by 0.039370! Then working out the coordinates.

I still have inch rulers but not everyone has them.

 

I currently use Microsoft Visio for CAD but might move to Libre when I don’t have work access anymore!  

 

Regards

Neil

 

Sent from Mail for Windows 10

 

From: Joost van der Waa
Sent: 12 November 2020 13:07
To: main@xtrackcad.groups.io
Subject: Re: [xtrackcad] Export DXF to Structure File (xtp) #Parameter #Structure

 

That would be a very nice tool !!!
I have been adding structures myself and it was a very tedious job with lots of errors before I was satisfied with the result, mainly because you are working in coordinates alone and have to do everything in inches where I am on the metric part of the planet.

Please don't count the enthusiasm on reactions in this group alone, there are many more XTrackCad user out there....

Joost

 


Joost van der Waa
 

Hi Neil,
I use Blender for my 3D-designs. Blender is a little bit difficult to learn, but once you overcome the first hurdle, you can design practically anything. You can find some examples on https://www.thingiverse.com/jvdwaa/designs


Adam Richards
 

Given that DXF is a universal CAD format, though, the choice of which tool to use is not important to the utility of interchange.

Here are two DXF files I created by quickly tracing a picture shot from from the top of the model box (I used LibreCAD, nice-looking, has some interesting UI workflow quirks, but I got around them).  I scaled the objects to be "real-world" (not at a particular scale) so they could be used as prototypes.   The idea would be to convert them into XTP as draw objects so they could be used as drawing elements when creating Car Prototypes (in this case in the br.xtp file). 

Adam
  


Adam Richards
 
Edited

On Thu, Nov 12, 2020 at 06:20 AM, Neil wrote:

A cad design tool import interface would be good and would save dividing mm measurements by exactly 25.3999 or close approximation 25.4 or multiply by 0.039370! Then working out the coordinates.

I still have inch rulers but not everyone has them.

Joost,

You may know this already, but in case, but most dimension boxes in XTrackCAD support entering dimensions in metric by adding mm (or m, or cm) after them (or for imperial/english as ft, in, ', ") regardless of layout setting. There is also support for entering a scale-dimensions and making them realworld or a realworld-dimensions and making them scale dimensions.  If you are set up for ft and fractional inches you can enter as decimal, etc.

Lengths and Distances can be entered in a variety of formats;

- 12ft 4 1/2in, 12' 4.5", 148.500, 1.234m, 123.4cm or 1234mm are all valid values.- Pressing the Equal Sign (=) key after an entry will reformat the value entered to your preferred length format.

- Pressing the "p" key after an entry will convert a prototype measurement to a scale measurement by dividing the value entered by the ratio for the current scale

- Pressing the "s" key after an entry will convert a scale measurement to a prototype measurement. 

Adam


Joost van der Waa
 

Hi Adam,
This information is new to me and very welcomed!
It will help for sure :-)
However, a tool to import DXF-files will be even better!
Joost


knorosow
 

Russell,

I like your idea. Its easier to use tools like LibreCAD, if you are used to.

Afaik LibreCAD is written in C++, not in C#. Furthermore there is a library associated with LC to handle DWG/DXF files (libdxfrw). So half of the work seems to be done already. You can get it by ‘git clone https://git.code.sf.net/p/libdxfrw/code libdxfrw-code’. Its C++ too.

Im not a programmer, though I got some scripting experience. If someone takes the lead, I would try to put me in.

- knorosow


Russell Shilling
 


Russell Shilling
 

Using that exporter, a LibreCAD drawing of a trestle from above and the turnout creation tool, I created this in the railroad:


--
Russell Shilling
http://shilling-or.com


Russell Shilling
 

I had a look at those drawings. All of the closed shapes have a specific color of Black, so they are all filled by DxfToXtp. Also, XTrackCad has no ellipse shape. Finally, I would have to add an option to create a rolling stock definition file as they are quite different than Structures, or the user would have to edit one manually. 
--
Russell Shilling
http://shilling-or.com


emrldsky
 

Tried to open the attached file, and got the following:

This was with version 5.1.2a.
Do I need a later version / beta?

Peace,
Mike G.


On 11/19/2020 4:19 PM, Russell Shilling wrote:
I had a look at those drawings. All of the closed shapes have a specific color of Black, so they are all filled by DxfToXtp. Also, XTrackCad has no ellipse shape. Finally, I would have to add an option to create a rolling stock definition file as they are quite different than Structures, or the user would have to edit one manually. 
--
Russell Shilling
http://shilling-or.com


Adam Richards
 

Good point re: ovals and filled ovals.  That is another drawing feature item for future enhancement to add to - 

  • Lines with arrows at the ends
  • Notations
    • Angular dimensions. 
    • Short linear dimensions using outside arrows (where the text length exceeds the line length).
    • Possibly call-outs (Line plus arrows leading to attached text box).
Adam


Russell Shilling
 

I've been using version 5.1.2a. I'm not that experienced with XTC, but that filename looks munged. Windows or something added a "-1.txt" to it somewhere along the line. I can load it, but it's loaded as a structure, so it's enormous. 

At some point I might work some more on this and make it handle rolling stock (CARPROTO) as well as structures. 
--
Russell Shilling
http://shilling-or.com


Dwyane Ward
 

Russell.

A few suggestion;

1. Adjust the output format for all elements to what Xtrkcad outputs, as example:

Yours

Y3 0 0.010417 4
        11 2 0
        19 2 0
        19 0 0
        11 0 0
End

Xtrkcad

Y4 0 0.000000 4 0
        1.500000 2.000000 0
        2.500000 2.000000 0
        2.500000 1.750000 0
        1.500000 1.750000 0
END$SEGS

You can find this formatting info on the wiki xtrkcad site.  http://xtrkcad-fork.sourceforge.net/Wikka/FileFormats

2. Change the F3/Y3 to the current F4/Y4 elements.

3. Ability to append another definition into an existing parameter file.
--
Dwyane Ward


Russell Shilling
 

Dwyane, here is a solution. 

Readme
DXF to XTP
 
Command line: 
 
DxfToXtp [-c "Contents"] <filename>
Reads from filename.dxf and creates filename.xtp with default filename.xtp
    
DxfToXtp [-c "Contents"] <xtp-filename> <filename1> [<filename2> ...]
Reads from each filename#.dxf and creates xtp-filename.xtp
 
The -c option specifies the Contents string. If not specified
the contents defaults to "XtpToDxf Structures".
 
You can also drag a file onto the program icon, which is as
if a single filename was supplied. 
 
Requires Windows and .NET framework.
 
 
DxfToXtp by Russell Shilling 2020
 
-----------------------------------------------------------
 
This utility will take a LibreCAD drawing (DXF) and convert 
it into an XTrackCAD parameter file (XTP). In order to make 
a 2D line drawing into a parameter file with filled shapes 
and lines, there are a couple rules to follow. For most 
entities in the drawing, using the default color (By Layer) 
will give satisfactory results. For shapes that can be 
filled the filled state is indicated by setting a discrete 
color on the entity - not letting it default to the layer.
 
The types of entities that this utility can convert are 
ARC, CIRCLE, LINE and POLYLINE. The CIRCLE and POLYLINE may 
be filled. 
 
A TEXT entity in the drawing may be used to specify the
Scale, Manufacturer, Description and Part Number. Separate
these with a pipe character. For example: 
        O|Lionel|Water Tower (Kit)|6-12711
 
Even though I specify LibreCAD, any DXF may be used, but
there are some LibreCAD specific rules that other programs
may not follow.
 
-----------------------------------------------------------
 
Included is a simple TEST.DXF that that can be dropped on
the DxfToXtp program to easily create TEST.XTP. In the 
Sample.zip are four DXF drawings (Rico Depot, Rico Tank and
Rico Pocket) and a command file MKRICO.CMD. Executing 
MKRICO (double-click) will build  RICO.XTP, containing those 
three structures. 
 
--
Russell Shilling
http://shilling-or.com


Russell Shilling
 

I have updated the DxfToXtp utility. Now it will create Structure and Composite Track objects. There are examples of both in the zip file. 
--
Russell Shilling
http://shilling-or.com


Milt Perkins
 

Russell,

Just found this post. Thank you for taking the time to produce this code as it will save me a lot of time. 

Milt


Russell Shilling
 

Happy to do it. I wanted a way to take my CAD drawings and convert them to structures. It grew from there.

Be sure to share what you've done if it might be useful to other modelers. 
--
Russell Shilling
http://shilling-or.com