Using Macros with Visual Studios Program

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Using Macros with Visual Studios Program

Post by triplus »

Further testing if i change units back to mm in LibreCAD dimension text changes from 1Inch to 25,4mm when i reopen the DXF file. Therefore i am guessing this doesn't happen for you? You would therefore always get 25,4mm in AutoCAD?
Korslight
Posts: 33
Joined: Thu Aug 11, 2016 3:26 pm

Re: Using Macros with Visual Studios Program

Post by Korslight »

I apologize for not doing a very good job at explaining myself.

The issue is due to both of the software I am using as being "unitless." So if I create a part that is 1"x1" using FreeCAD and export it as a dxf. It will import into AutoCAD and my nesting software (SigmaNEST) as being 25.4"x25.4" no matter how I have exported the part in FreeCAD.

I have attached what I am referring to. Did I miss a setting along the way? Anything I may be doing incorrectly?

I have not used LibreCAD so I am unsure how the program works with scaling.

**Edited to also show AutoCAD import**
Attachments
Autocad.JPG
Autocad.JPG (17.3 KiB) Viewed 1160 times
Metric.JPG
Metric.JPG (41.98 KiB) Viewed 1161 times
Unit_setting.JPG
Unit_setting.JPG (26.13 KiB) Viewed 1161 times
Drawing.JPG
Drawing.JPG (24.45 KiB) Viewed 1161 times
Korslight
Posts: 33
Joined: Thu Aug 11, 2016 3:26 pm

Re: Using Macros with Visual Studios Program

Post by Korslight »

I guess a simple work-around for this if nothing else would be to code in a scale as seen in the code below:

Code: Select all

>>>Draft.scale([FreeCAD.ActiveDocument.DWire],delta=FreeCAD.Vector(0.0393700787402,0.0393700787402,0.0),center=FreeCAD.Vector(0.0,0.0,0.0),copy=False)
>>> FreeCAD.ActiveDocument.recompute()
>>>Draft.scale([FreeCAD.ActiveDocument.DWire],delta=FreeCAD.Vector(0.0393700787402,0.0393700787402,0.0393700787402),center=FreeCAD.Vector(0.0,0.0,0.0),copy=False)
>>> FreeCAD.ActiveDocument.recompute()
This way I can scale it to what I need based on what I am doing (assuming I am exporting incorrectly :) ).
Last edited by Korslight on Mon Aug 15, 2016 9:29 pm, edited 1 time in total.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Using Macros with Visual Studios Program

Post by triplus »

I don't have AutoCAD to test things out but LibreCAD is "smart enough" to do the correct thing. That is after DXF file is exported and opened in LibreCAD dimension value will adjust based on the LibreCAD general unit set (mm/Inch).

Therefore if the same file is opened when LibreCAD general unit is set to Inch dimension will have 1Inch value. When LibreCAD general unit is set to mm dimension will have 25,4mm value.

No scaling is going on here just unit conversion done correctly.

Therefore i would say for now forget about FreeCAD side of things and focus on AutoCAD if it has any settings that works like this.
Korslight
Posts: 33
Joined: Thu Aug 11, 2016 3:26 pm

Re: Using Macros with Visual Studios Program

Post by Korslight »

triplus,

I agree, I would like to get this figured out. Here is one quick test I did by creating a part in Inventor 2014 and importing into AutoCAD and FreeCAD. Please let me know if I should do this test another way or provide more information.

The square is 5" x 5". It was also the same in Autodesk, but imported differently into FreeCAD (at 0.196"). I also imported it into the free https://a360.autodesk.com/viewer. I understand this isn't a great comparison since all the testing is done with Autodesk products.

I have attached the images below.

What happens if you upload your model to the A360 viewer?

Thank you again for your time on helping me troubleshoot this.
Attachments
4 Inventor_Drawing.JPG
4 Inventor_Drawing.JPG (28.23 KiB) Viewed 1155 times
3 Autocad.JPG
3 Autocad.JPG (20.88 KiB) Viewed 1155 times
2 FreeCAD.JPG
2 FreeCAD.JPG (58.17 KiB) Viewed 1155 times
1 A360 Viewer.JPG
1 A360 Viewer.JPG (28.42 KiB) Viewed 1155 times
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Using Macros with Visual Studios Program

Post by triplus »

I feel that any potential issues when importing DXF file in FreeCAD could end up being totally different and unrelated thing. The way i understand it you are trying to achieve the following:

Export DXF with dimensions from FreeCAD and open it in AutoCAD after? The issue you are having is units aren't converted correctly? Therefore we should focus on this for now.

I looked for information on the internet about AutoCAD DXF import capabilities but only found this reference for 3D MAX DWG/DXF Import: Geometry Panel:
Incoming file units
This drop-down list lets you specify the base units in the incoming file. Available only when Rescale is on.
Rescale
Allows rescaling the incoming geometry by a factor corresponding to the most common unit type used. The importer tries to detect the units of the DWG file being imported, compares those units with the 3ds Max system units, and then provides the appropriate conversion factor.

For example, if a drawing file is built in millimeters and 3ds Max has its System Units set to inches, the AutoCAD DWG/DXF Import Options dialog automatically has Rescale on and the Incoming File Units set to millimeters.
https://knowledge.autodesk.com/support/ ... 2-htm.html

If AutoCAD has something like that try it out (but i am not sure if you actually do want any "scaling" beyond dimension unit value conversion). If not i guess you could explore the option to use LibreCAD as intermediate step to get the result you are after. As when it comes to LibreCAD it does look like it can produce the results you are after.
jobdelacruz
Posts: 1
Joined: Mon Jun 18, 2018 1:32 pm

Re: Using Macros with Visual Studios Program

Post by jobdelacruz »

Good read that there is an old post on how to implement Freecad via C#. Not sure if you already resolved the issue regarding the scaling. Did you set your AutoCAD units in the right settings under Drawing setup. This should resolve the drawing scale from an imported file.

Btw, I am an Autodesk product user mainly AutoCAD and Inventor. I started learning programming in Ilogic and now using C#. I see a great potential in implementing freeCAD in some of our projects since Inventor is expensive and not all know how to use CAD software. I already have some forms and database to retrieve dimensions. Now I just I have to learn the basic of freeCAD and macro so I can throw information's coming from .net form. Hope you can share some basic implementation and ideas in the future. ;)

Korslight wrote: Mon Aug 15, 2016 9:06 pm I apologize for not doing a very good job at explaining myself.

The issue is due to both of the software I am using as being "unitless." So if I create a part that is 1"x1" using FreeCAD and export it as a dxf. It will import into AutoCAD and my nesting software (SigmaNEST) as being 25.4"x25.4" no matter how I have exported the part in FreeCAD.

I have attached what I am referring to. Did I miss a setting along the way? Anything I may be doing incorrectly?

I have not used LibreCAD so I am unsure how the program works with scaling.

**Edited to also show AutoCAD import**
Post Reply