View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0001738 | File formats | General | public | 2014-09-10 12:00 | 2017-07-15 11:12 |
| Reporter | herman15 | Assigned To | vejmarie | ||
| Priority | normal | Severity | feature | Reproducibility | always |
| Status | closed | Resolution | fixed | ||
| Product Version | 0.14 | ||||
| Summary | 0001738: IDF Import failure if STP file consists of multiple Objects | ||||
| Description | IDf import script failure if STP file consists of multiple Objects If multiple Objects are in STP file only first(or last) is placed correctly. All other objects are placed at origin and these parts are not grouped correctly. Solution: In IDF.py import script add multi Object support in function place_steps. i have attached a modified place_step routine which is sufficient for me at least. | ||||
| Tags | STEP | ||||
| FreeCAD Information | |||||
|
|
Idf_place_steps.py (4,948 bytes)
def place_steps(doc,placement,board_thickness):
""" place_steps(doc,placement,board_thickness)->place step models on board
list of models and path to step files is set at start of this script
model_tab_filename= "" & step_path="" """
model_file=pythonopen(model_tab_filename, "r")
model_lines=model_file.readlines()
model_file.close()
model_dict=[]
if IDF_diag==1:
model_file=pythonopen(IDF_diag_path+"/missing_models.lst", "w")
keys=[]
#prev_step="*?.*?" #hope nobody will insert this step filename
step_dict=[]
for model_line in model_lines:
model_records=split_records(model_line)
if len(model_records)>1 and model_records[0] and not model_records[0] in keys:
keys.append(model_records[0])
model_dict.append((str(model_records[0]).replace('"',''),str(model_records[1]).replace('"','')))
model_dict=dict(model_dict)
validkeys=filter(lambda x:x in [place_item[2] for place_item in placement], model_dict.keys())
FreeCAD.Console.PrintMessage("Step models to be loaded for footprints: "+str(validkeys)+"\n")
grp=doc.addObject("App::DocumentObjectGroup", "Step Lib")
for validkey in validkeys:
# Store Object List before inserting STP Model
prevObj = doc.Objects
# Reset new Object List
newObj = []
# Reset new Object List Counter
newObjCnt=0
# Inserting STP Model
ImportGui.insert(step_path+model_dict[validkey],FreeCAD.ActiveDocument.Name)
# Store Object List after inserting STP Model
aftObj = doc.Objects
# Check the differences and store to List
for d in aftObj:
if not d in prevObj:
newObj.append(d)
# Loop through all new added Objects
for impPart in newObj:
impPart.ViewObject.Visibility=0
# Label: validKey if only 1 Object is available; validkey+"0001" for second object ...
if newObjCnt>0:
st = "%s%04d" % (validkey, newObjCnt)
impPart.Label=st
else:
impPart.Label=validkey
# Debug Message to Console
FreeCAD.Console.PrintMessage("New Object "+str(d.Name)+": "+str(impPart.Label)+"\n")
# Add Object to Group
grp.addObject(impPart)
# Add Object to Step Dictionary
step_dict.append((impPart.Label,impPart))
# Increment Counter
newObjCnt+=1
#partName=FreeCAD.ActiveDocument.ActiveObject.Name
# impPart=FreeCAD.ActiveDocument.ActiveObject
#impPart.Shape=FreeCAD.ActiveDocument.ActiveObject.Shape
#impPart.ViewObject.DiffuseColor=FreeCAD.ActiveDocument.ActiveObject.ViewObject.DiffuseColor
# impPart.ViewObject.Visibility=0
# impPart.Label=validkey
# grp.addObject(impPart)
# step_dict.append((validkey,impPart))
FreeCAD.Console.PrintMessage("Reading step file "+str(model_dict[validkey])+" for footprint "+str(validkey)+"\n")
step_dict=dict(step_dict)
grp=doc.addObject("App::DocumentObjectGroup", "Step Models")
for place_item in placement:
if step_dict.has_key(place_item[2]):
step_model=doc.addObject("Part::Feature",place_item[0]+"_s")
FreeCAD.Console.PrintMessage("Adding STEP model "+str(place_item[0])+"\n")
#if prev_step!=place_item[2]:
# model0=Part.read(step_path+"/"+model_dict[place_item[2]])
# prev_step=place_item[2]
step_model.Shape=step_dict[place_item[2]].Shape
step_model.ViewObject.DiffuseColor=step_dict[place_item[2]].ViewObject.DiffuseColor
z_pos=0
rotateY=0
if place_item[6]=='BOTTOM':
rotateY=pi
z_pos=-board_thickness
placmnt=Base.Placement(Base.Vector(place_item[3],place_item[4],z_pos),toQuaternion(rotateY,place_item[5]*pi/180,0))
step_model.Placement=placmnt
grp.addObject(step_model)
# Check if more than one Object is available
newObjCnt=1
st = "%s%04d" % (place_item[2], newObjCnt)
FreeCAD.Console.PrintMessage("Has Key "+st+"? "+"\n")
while step_dict.has_key(st):
cntst = "%04d" %newObjCnt
FreeCAD.Console.PrintMessage("Has Key "+st+"! "+"\n")
step_model=doc.addObject("Part::Feature",place_item[0]+"_s"+cntst)
step_model.Shape=step_dict[st].Shape
step_model.ViewObject.DiffuseColor=step_dict[st].ViewObject.DiffuseColor
step_model.Placement=placmnt
grp.addObject(step_model)
newObjCnt+=1
st = "%s%04d" % (place_item[2], newObjCnt)
else:
if IDF_diag==1:
model_file.writelines(str(place_item[0])+" "+str(place_item[2])+"\n")
if IDF_diag==1:
model_file.close()
|
|
|
It might be fixed in FreeCAD Pull Request 871 which is changing the STEP file importer behavior from absolute to relative placement. We are also better supporting reference shapes into Step and I believe that this bug is fixed even if I could not test it, I had the same behavior on some very complex test case (not IDF but native step) |
|
|
@herman15 could you possibly test on the latest bleeding edge 0.17 revision ? |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2014-09-10 12:00 | herman15 | New Issue | |
| 2014-09-10 12:00 | herman15 | File Added: Idf_place_steps.py | |
| 2017-01-11 03:19 | Kunda1 | Tag Attached: STEP | |
| 2017-01-16 18:54 | Kunda1 | Project | FreeCAD => File formats |
| 2017-01-16 18:54 | Kunda1 | Category | Patch => General |
| 2017-02-04 12:20 | Kunda1 | Relationship added | related to 0002369 |
| 2017-03-27 12:53 | Kunda1 | Assigned To | => vejmarie |
| 2017-03-27 12:53 | Kunda1 | Status | new => assigned |
| 2017-07-11 07:58 | vejmarie | Note Added: 0009705 | |
| 2017-07-11 10:53 | Kunda1 | Relationship added | related to 0003076 |
| 2017-07-11 10:55 | Kunda1 | Note Edited: 0009705 | |
| 2017-07-11 17:03 | Kunda1 | Status | assigned => resolved |
| 2017-07-11 17:03 | Kunda1 | Resolution | open => fixed |
| 2017-07-11 17:04 | Kunda1 | Note Added: 0009716 | |
| 2017-07-15 11:12 | Kunda1 | Status | resolved => closed |
FreeCAD