Import.export change in 0.17

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
uuykay
Posts: 13
Joined: Mon May 14, 2018 5:51 am

Import.export change in 0.17

Postby uuykay » Fri May 18, 2018 7:24 am

Hi everyone,

I currently have a problem where the STP export I am getting from Import.export(array_of_parts, path_to_dump_file) is not correctly positioning all the parts. It was working perfectly in 0.16. Please take a look at the images below for 0.17 and then for 0.16 respectively.

Image
Image
Image



Above is the function I am running. The for loop i wrote here is irrelevant, if you run Import.export(array_of_parts, path_to_dump_file) with any array of parts to dump, the alignments are messed up. Can anyone from the FreeCAD team comment on whether something in Import.export has changed?

William
User avatar
easyw-fc
Posts: 2614
Joined: Thu Jul 09, 2015 9:34 am

Re: Import.export change in 0.17

Postby easyw-fc » Fri May 18, 2018 8:54 am

uuykay wrote:
Fri May 18, 2018 7:24 am
Hi everyone,

I currently have a problem where the STP export I am getting from Import.export(array_of_parts, path_to_dump_file) is not correctly positioning all the parts. It was working perfectly in 0.16. Please take a look at the images below for 0.17 and then for 0.16 respectively.

Above is the function I am running. The for loop i wrote here is irrelevant, if you run Import.export(array_of_parts, path_to_dump_file) with any array of parts to dump, the alignments are messed up. Can anyone from the FreeCAD team comment on whether something in Import.export has changed?

William
In FC 0.17 you need to put all your STEP objects inside a 'Part' Design Next container to let the exporter keeping the relative placement.
This is what the other commercial sw should be doing.

EDIT: it should be working also in FC0.17 as previous without the need of the Part container...
would you please post an example file and your FC release details?
uuykay
Posts: 13
Joined: Mon May 14, 2018 5:51 am

Re: Import.export change in 0.17

Postby uuykay » Fri May 18, 2018 11:00 am

Thank you very much for your reply. Can you please point me to how I might be able to implement a "Part' Design Next container"?

I will post up some sample code on Monday. You guys offer great support and I love this forum and this product.
uuykay
Posts: 13
Joined: Mon May 14, 2018 5:51 am

Re: Import.export change in 0.17

Postby uuykay » Mon May 21, 2018 1:37 am

easyw-fc wrote:
Fri May 18, 2018 8:54 am
In FC 0.17 you need to put all your STEP objects inside a 'Part' Design Next container to let the exporter keeping the relative placement.
This is what the other commercial sw should be doing.

EDIT: it should be working also in FC0.17 as previous without the need of the Part container...
would you please post an example file and your FC release details?
Hi easyw-fc, please see this simplified script of what I am trying to accomplish. I have created a cylinder and box feature. I created a placement matrix to position the cylinder (the position is just made up as an example) and applied it to the cyl.Shape. I then run the Import.export command to dump the two part features into a .stp file. When I open the .stp file, the placement on the cylinder is not carried across / saved as you can see.

Image

Image

Code: Select all

import FreeCAD
import Part
import Import

doc = FreeCAD.newDocument()


def genPlacementMatrix():
    yaw = 5000
    pitch = 3000
    roll = 2200

    pos = FreeCAD.Vector(0, 0, 0)
    rot = FreeCAD.Rotation(yaw, pitch, roll)
    center = FreeCAD.Vector(0, 0, 0)
    newplace = FreeCAD.Placement(pos, rot, center)

    return newplace

# Generate a placement matrix
newplace = genPlacementMatrix()

stem_radius = 2
stem_length = 5
cyl = FreeCAD.ActiveDocument.addObject("Part::Feature", "Cylinder")
cyl_pos_vec = FreeCAD.Vector(0, 0, 0)
cyl_dir_vec = FreeCAD.Vector(0, 0, -1)
cyl_shape = Part.makeCylinder(
    stem_radius, stem_length, cyl_pos_vec, cyl_dir_vec)
# Set the placement to the cylinder
cyl_shape.Placement = newplace
cyl.Shape = cyl_shape

# Create a box, don't worry about placement here
box_length = 2
box_width = 2
box_height = 2
box = FreeCAD.ActiveDocument.addObject("Part::Feature", "Box")
box.Shape = Part.makeBox(box_length, box_width, box_height)

# Create a list of the cyl and box part features
shapeobjs = [cyl, box]
# Set the dump path
dump_path = 'D:/GoogleDrive/Product/Connections/FreeCAD/LocalTests/dump.stp'
# Do the dumping
Import.export(shapeobjs, dump_path)
uuykay
Posts: 13
Joined: Mon May 14, 2018 5:51 am

Re: Import.export change in 0.17

Postby uuykay » Mon May 21, 2018 1:38 am

Also my release details are:

OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.13522 (Git)
Build type: Release
Branch: releases/FreeCAD-0-17
Hash: 3bb5ff4e70c0c526f2d9dd69b1004155b2f527f2
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: English/Australia (en_AU)
User avatar
easyw-fc
Posts: 2614
Joined: Thu Jul 09, 2015 9:34 am

Re: Import.export change in 0.17

Postby easyw-fc » Mon May 21, 2018 7:28 am

uuykay wrote:
Mon May 21, 2018 1:37 am
Hi easyw-fc, please see this simplified script of what I am trying to accomplish. I have created a cylinder and box feature. I created a placement matrix to position the cylinder (the position is just made up as an example) and applied it to the cyl.Shape. I then run the Import.export command to dump the two part features into a .stp file. When I open the .stp file, the placement on the cylinder is not carried across / saved as you can see.

Code: Select all

import FreeCAD
import Part
import Import

doc = FreeCAD.newDocument()


def genPlacementMatrix():
    yaw = 5000
    pitch = 3000
    roll = 2200

    pos = FreeCAD.Vector(0, 0, 0)
    rot = FreeCAD.Rotation(yaw, pitch, roll)
    center = FreeCAD.Vector(0, 0, 0)
    newplace = FreeCAD.Placement(pos, rot, center)

    return newplace

# Generate a placement matrix
newplace = genPlacementMatrix()

stem_radius = 2
stem_length = 5
cyl = FreeCAD.ActiveDocument.addObject("Part::Feature", "Cylinder")
cyl_pos_vec = FreeCAD.Vector(0, 0, 0)
cyl_dir_vec = FreeCAD.Vector(0, 0, -1)
cyl_shape = Part.makeCylinder(
    stem_radius, stem_length, cyl_pos_vec, cyl_dir_vec)
# Set the placement to the cylinder
cyl_shape.Placement = newplace
cyl.Shape = cyl_shape

# Create a box, don't worry about placement here
box_length = 2
box_width = 2
box_height = 2
box = FreeCAD.ActiveDocument.addObject("Part::Feature", "Box")
box.Shape = Part.makeBox(box_length, box_width, box_height)

# Create a list of the cyl and box part features
shapeobjs = [cyl, box]
# Set the dump path
dump_path = 'D:/GoogleDrive/Product/Connections/FreeCAD/LocalTests/dump.stp'
# Do the dumping
Import.export(shapeobjs, dump_path)
just change your code from:

Code: Select all

# Create a list of the cyl and box part features
shapeobjs = [cyl, box]
to:

Code: Select all

shapeobjs = []
shapeobjs.append(cyl)
shapeobjs.append(box)
and you should be fine
uuykay
Posts: 13
Joined: Mon May 14, 2018 5:51 am

Re: Import.export change in 0.17

Postby uuykay » Mon May 21, 2018 12:20 pm

easyw-fc wrote:
Mon May 21, 2018 7:28 am
just change your code from:

Code: Select all

# Create a list of the cyl and box part features
shapeobjs = [cyl, box]
to:

Code: Select all

shapeobjs = []
shapeobjs.append(cyl)
shapeobjs.append(box)
and you should be fine
I tried it and it did not work. I encourage you to try running it for yourself. You just deep to change the dump path to a local directory on your computer. Your code above is equivalent anyways.
User avatar
easyw-fc
Posts: 2614
Joined: Thu Jul 09, 2015 9:34 am

Re: Import.export change in 0.17

Postby easyw-fc » Mon May 21, 2018 12:48 pm

uuykay wrote:
Mon May 21, 2018 12:20 pm
I tried it and it did not work. I encourage you to try running it for yourself. You just deep to change the dump path to a local directory on your computer. Your code above is equivalent anyways.
I did test it before posting the code, otherwise I wouldn't just have replied;
you may have a different configuration from mine...
exporting-test.gif
exporting-test.gif (658.02 KiB) Viewed 553 times
uuykay wrote:
Mon May 21, 2018 12:20 pm
Your code above is equivalent anyways.
it seems not...

and here the code

Code: Select all

import FreeCAD
import Part
import Import

doc = FreeCAD.newDocument()


def genPlacementMatrix():
    yaw = 5000
    pitch = 3000
    roll = 2200

    pos = FreeCAD.Vector(0, 0, 0)
    rot = FreeCAD.Rotation(yaw, pitch, roll)
    center = FreeCAD.Vector(0, 0, 0)
    newplace = FreeCAD.Placement(pos, rot, center)

    return newplace

# Generate a placement matrix
newplace = genPlacementMatrix()

stem_radius = 2
stem_length = 5
cyl = FreeCAD.ActiveDocument.addObject("Part::Feature", "Cylinder")
cyl_pos_vec = FreeCAD.Vector(0, 0, 0)
cyl_dir_vec = FreeCAD.Vector(0, 0, -1)
cyl_shape = Part.makeCylinder(
    stem_radius, stem_length, cyl_pos_vec, cyl_dir_vec)
# Set the placement to the cylinder
cyl_shape.Placement = newplace
cyl.Shape = cyl_shape

# Create a box, don't worry about placement here
box_length = 2
box_width = 2
box_height = 2
box = FreeCAD.ActiveDocument.addObject("Part::Feature", "Box")
box.Shape = Part.makeBox(box_length, box_width, box_height)

# Create a list of the cyl and box part features
shapeobjs = [cyl, box]
# Set the dump path
dump_path = 'c:/Temp/dump.stp'
dump_path2 = u"C:/Temp/dumb2.step"
dump_path3 = u"C:/Temp/dumb3.step"
# Do the dumping
Import.export(shapeobjs, dump_path)

__objs__=[]
__objs__.append(FreeCAD.ActiveDocument.getObject("Cylinder"))
__objs__.append(FreeCAD.ActiveDocument.getObject("Box"))
import ImportGui
ImportGui.export(__objs__,dump_path2)


__objs__=[]
__objs__.append(cyl)
__objs__.append(box)
import ImportGui
ImportGui.export(__objs__,dump_path3)

print(__objs__)
print(shapeobjs)


ImportGui.open(dump_path)
ImportGui.open(dump_path2)
ImportGui.open(dump_path3)
and my FC version
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.13721 (Git)
Build type: Release
Branch: master
Hash: afdd30b137cdfd096c61c4aee270025115d0f8d6
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: English/UnitedStates (en_US)
uuykay
Posts: 13
Joined: Mon May 14, 2018 5:51 am

Re: Import.export change in 0.17

Postby uuykay » Mon May 21, 2018 1:25 pm

I do appreciate your replies and the gif you provided was helpful, however there is a main point of difference between our two code bases. In your examples which worked (worked being defined as dumping and then re-opening and having the placement preserved) you were using "import ImportGui". Whilst using the FCMacro command I compared this with,

Code: Select all

shapeobjs = [cyl, box]
Import.export(shapeobjs, dump_path)
ImportGui.export(shapeobjs, dump_path2)
Now when I manually open the first dumped file, the placement is lost. When I opened the file dumped from ImportGui the placement is preserved. From this, it seems like the list definition is irrelevant, and is entirely based on the differences between Import and ImportGui. Unfortunately for my use case, I can't use ImportGui because I am trying to run a server set up with freecadcmd.

Please test and let me know if you come up with another solution


easyw-fc wrote:
Mon May 21, 2018 12:48 pm
uuykay wrote:
Mon May 21, 2018 12:20 pm
I tried it and it did not work. I encourage you to try running it for yourself. You just deep to change the dump path to a local directory on your computer. Your code above is equivalent anyways.
I did test it before posting the code, otherwise I wouldn't just have replied;
you may have a different configuration from mine...

exporting-test.gif
uuykay wrote:
Mon May 21, 2018 12:20 pm
Your code above is equivalent anyways.
it seems not...

and here the code

Code: Select all

import FreeCAD
import Part
import Import

doc = FreeCAD.newDocument()


def genPlacementMatrix():
    yaw = 5000
    pitch = 3000
    roll = 2200

    pos = FreeCAD.Vector(0, 0, 0)
    rot = FreeCAD.Rotation(yaw, pitch, roll)
    center = FreeCAD.Vector(0, 0, 0)
    newplace = FreeCAD.Placement(pos, rot, center)

    return newplace

# Generate a placement matrix
newplace = genPlacementMatrix()

stem_radius = 2
stem_length = 5
cyl = FreeCAD.ActiveDocument.addObject("Part::Feature", "Cylinder")
cyl_pos_vec = FreeCAD.Vector(0, 0, 0)
cyl_dir_vec = FreeCAD.Vector(0, 0, -1)
cyl_shape = Part.makeCylinder(
    stem_radius, stem_length, cyl_pos_vec, cyl_dir_vec)
# Set the placement to the cylinder
cyl_shape.Placement = newplace
cyl.Shape = cyl_shape

# Create a box, don't worry about placement here
box_length = 2
box_width = 2
box_height = 2
box = FreeCAD.ActiveDocument.addObject("Part::Feature", "Box")
box.Shape = Part.makeBox(box_length, box_width, box_height)

# Create a list of the cyl and box part features
shapeobjs = [cyl, box]
# Set the dump path
dump_path = 'c:/Temp/dump.stp'
dump_path2 = u"C:/Temp/dumb2.step"
dump_path3 = u"C:/Temp/dumb3.step"
# Do the dumping
Import.export(shapeobjs, dump_path)

__objs__=[]
__objs__.append(FreeCAD.ActiveDocument.getObject("Cylinder"))
__objs__.append(FreeCAD.ActiveDocument.getObject("Box"))
import ImportGui
ImportGui.export(__objs__,dump_path2)


__objs__=[]
__objs__.append(cyl)
__objs__.append(box)
import ImportGui
ImportGui.export(__objs__,dump_path3)

print(__objs__)
print(shapeobjs)


ImportGui.open(dump_path)
ImportGui.open(dump_path2)
ImportGui.open(dump_path3)
and my FC version
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.13721 (Git)
Build type: Release
Branch: master
Hash: afdd30b137cdfd096c61c4aee270025115d0f8d6
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: English/UnitedStates (en_US)
User avatar
easyw-fc
Posts: 2614
Joined: Thu Jul 09, 2015 9:34 am

Re: Import.export change in 0.17

Postby easyw-fc » Mon May 21, 2018 1:53 pm

uuykay wrote:
Mon May 21, 2018 1:25 pm
I do appreciate your replies and the gif you provided was helpful, however there is a main point of difference between our two code bases. In your examples which worked (worked being defined as dumping and then re-opening and having the placement preserved) you were using "import ImportGui". Whilst using the FCMacro command I compared this with,
...
Now when I manually open the first dumped file, the placement is lost. When I opened the file dumped from ImportGui the placement is preserved. From this, it seems like the list definition is irrelevant, and is entirely based on the differences between Import and ImportGui. Unfortunately for my use case, I can't use ImportGui because I am trying to run a server set up with freecadcmd.
Sorry I missed the non Gui server part, looking at the colors of your images.

This seems definitively a bug to be submitted for Import.export code vs. ImportGui.export version.