View Issue Details

IDProjectCategoryView StatusLast Update
0002821FreeCADPatchpublic2021-02-06 06:49
Reporterstefan.althoefer Assigned To 
PrioritylowSeverityminorReproducibilityalways
Status feedbackResolutionreopened 
PlatformFreeCAD 
Product Version0.16 
Target Version0.20 
Summary0002821: IDF Import of Step Models
DescriptionHi,

I'm using IDF module to import IDF Files written by Pulsonix.

I found that working with external Step models (by footprint_models.csv)
could be better.

The attached patch addresses three issues:
1. Difficulties in matching. I removed quotes from some strings
    before using them
2. Read the step model now with Part.Shape.read() instead of using
    ImportGui.insert(). This has the advantage to work even if the Step
    Model has more than one solid/object.
3. Ability to hide/remove EMP generated models when a Step file for
    a component was loaded. Without this you end up with the Step Model
    and the EMP model overlap.

Although I tested with 0.16, the patch should apply to the current git.

Sorry I'm not a git user, and neither a Python programmer ...
Additional InformationForum thread: https://forum.freecadweb.org/viewtopic.php?f=8&t=31627
Tags#pending, import, STEP
FreeCAD Information

Activities

stefan.althoefer

2016-12-28 11:57

reporter  

idf.py.patch (Attachment missing)

Kunda1

2017-01-17 20:43

administrator   ~0007854

Reminder sent to: shoogen

Hey @shoogen do you have a moment to address this ticket(patch) ? Thanks

Kunda1

2017-01-28 13:25

administrator   ~0008055

Note: @vejmarie will check this ticket soon.

Kunda1

2017-03-23 23:57

administrator   ~0008693

changing to feedback to keep track of ticket.

Kunda1

2017-06-01 19:15

administrator   ~0009246

@stefan.althoefer do you mind reattaching the .py script?

Kunda1

2017-06-16 15:55

administrator   ~0009415

@stefan.althoefer ping

Kunda1

2017-06-28 22:12

administrator   ~0009586

@vejmarie I can't get OP to respond. Can you take a look/see and offer yours opinion?

Kunda1

2017-07-11 20:19

administrator   ~0009719

@stefan.althoefer ping

Kunda1

2017-08-13 16:57

administrator   ~0009916

@vejmarie please weigh in. Can I close this ticket?

Kunda1

2017-09-24 19:29

administrator   ~0010173

@vejmarie ping

stefan.althoefer

2018-07-06 22:07

reporter   ~0011498

Sorry for not having responded to all the pings. But here I'm back with
this issue. Mainly because I switched to 0.17 with the same issues and
had to recreate my patch.

The issues/improvements are exactly the same as in the original description.

My IDF looks like this:


"SOT23" "BSS138 SOT23" T300
-64.77 -10.795 0.0 TOP PLACED
"SOT23" "BSS138 SOT23" T400
-72.627 21.351 270.0 TOP PLACED
"RES_SMD_0805_JUMPA" "0_JMP RES_SMD_0805_JUMP" R460
-75.75 36 0.0 BOTTOM PLACED
"RES_SMD_0805_JUMPA" "0_JMP RES_SMD_0805_JUMP" R461
-75.75 34.25 0.0 BOTTOM PLACED

With the original idf.py, the scanned input looked like this

['T300', '"BSS138 SOT23"', '"SOT23"', -64.77, -10.795, 0.0, 'TOP', 'PLACED']
['T400', '"BSS138 SOT23"', '"SOT23"', -72.627, 21.351, 270.0, 'TOP', 'PLACED']
['R460', '"0_JMP RES_SMD_0805_JUMP"', '"RES_SMD_0805_JUMPA"', -75.75, 36.0, 0.0, 'BOTTOM', 'PLACED']
['R461', '"0_JMP RES_SMD_0805_JUMP"', '"RES_SMD_0805_JUMPA"', -75.75, 34.25, 0.0, 'BOTTOM', 'PLACED']

Obviously, the double quote should be eliminated, or matching with external
step model files will not work.
My fix just replaces double quotes with nothing. It is very unlikely that double quotes will be part of the Component names. Perhaps it would be better to fix split_records()?


*** Idf-git.py	2018-07-06 23:26:28.250000000 +0200
--- Idf-clean.py	2018-07-06 23:48:30.444397500 +0200
***************
*** 49,54 ****
--- 49,55 ----
  IDF_diag=0 # 0/1=disabled/enabled output (footprint.lst/missing_models.lst) 
  IDF_diag_path="/tmp" # path for output of footprint.lst and missing_models.lst
  
+ EMP_remove=2 # 0=leave, 1=hide, 2=remove EMP model when step has been found
  
  ########################################################################################
  #              End config section do not touch code below                              #
***************
*** 114,122 ****
            drills.append([float(emnrecords[0])*emn_unit,float(emnrecords[1])*emn_unit,float(emnrecords[2])*emn_unit])
         if current_section==".PLACEMENT"  and section_counter>1 and fmod(section_counter,2)==0:
            place_item=[]
!           place_item.append(emnrecords[2]) #Reference designator
!           place_item.append(emnrecords[1]) #Component part number
!           place_item.append(emnrecords[0]) #Package name
         if current_section==".PLACEMENT"  and section_counter>1 and fmod(section_counter,2)==1:
            place_item.append(float(emnrecords[0])*emn_unit) #X
            place_item.append(float(emnrecords[1])*emn_unit) #Y
--- 115,123 ----
            drills.append([float(emnrecords[0])*emn_unit,float(emnrecords[1])*emn_unit,float(emnrecords[2])*emn_unit])
         if current_section==".PLACEMENT"  and section_counter>1 and fmod(section_counter,2)==0:
            place_item=[]
!           place_item.append(str(emnrecords[2]).replace('"','')) #Reference designator
!           place_item.append(str(emnrecords[1]).replace('"','')) #Component part number
!           place_item.append(str(emnrecords[0]).replace('"','')) #Package name
         if current_section==".PLACEMENT"  and section_counter>1 and fmod(section_counter,2)==1:
            place_item.append(float(emnrecords[0])*emn_unit) #X
            place_item.append(float(emnrecords[1])*emn_unit) #Y
***************
*** 265,272 ****
          emp_unit=1
       if (current_section==".ELECTRICAL" or current_section==".MECHANICAL") and section_counter==2:
          comp_outline=[] #no part outline
!         comp_GeometryName=emprecords[0] # geometry name
!         comp_PartNumber=emprecords[1] # Part Number
          comp_height=emp_unit*float(emprecords[3]) # Comp Height
       if (current_section==".ELECTRICAL" or current_section==".MECHANICAL") and section_counter>2:
          comp_outline.append([float(emprecords[1])*emp_unit,float(emprecords[2])*emp_unit,float(emprecords[3])]) #add point of outline
--- 266,273 ----
          emp_unit=1
       if (current_section==".ELECTRICAL" or current_section==".MECHANICAL") and section_counter==2:
          comp_outline=[] #no part outline
!         comp_GeometryName=str(emprecords[0]).replace('"','') # geometry name
!         comp_PartNumber=str(emprecords[1]).replace('"','') # Part Number
          comp_height=emp_unit*float(emprecords[3]) # Comp Height
       if (current_section==".ELECTRICAL" or current_section==".MECHANICAL") and section_counter>2:
          comp_outline.append([float(emprecords[1])*emp_unit,float(emprecords[2])*emp_unit,float(emprecords[3])]) #add point of outline
***************
*** 349,363 ****
      FreeCAD.Console.PrintMessage("Step models to be loaded for footprints: "+str(validkeys)+"\n")
      grp=doc.addObject("App::DocumentObjectGroup", "Step Lib")
      for validkey in validkeys:
!          ImportGui.insert(step_path+model_dict[validkey],FreeCAD.ActiveDocument.Name)
!          #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")
--- 350,362 ----
      FreeCAD.Console.PrintMessage("Step models to be loaded for footprints: "+str(validkeys)+"\n")
      grp=doc.addObject("App::DocumentObjectGroup", "Step Lib")
      for validkey in validkeys:
!          shape=Part.Shape()
!          shape.read(step_path+model_dict[validkey])
!          shapeobj = doc.addObject("Part::Feature",validkey)
!          shapeobj.Shape = shape
!          shapeobj.ViewObject.Visibility=0
!          grp.addObject(shapeobj)
!          step_dict.append((validkey,shapeobj))
           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")
***************
*** 378,383 ****
--- 377,389 ----
          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)
+         if EMP_remove==1:
+            empobj = doc.getObject(place_item[0])
+            # Fixme: should check if the object really exists?
+            empobj.ViewObject.Visibility=0
+         if EMP_remove==2:
+            # Fixme: should check if the object really exists?
+            FreeCAD.ActiveDocument.removeObject(place_item[0])
        else: 
          if IDF_diag==1:
              model_file.writelines(str(place_item[0])+" "+str(place_item[2])+"\n")

stefan.althoefer

2018-07-06 22:14

reporter   ~0011499

I see that there is no demo IDF file set in the distribution. If you lack such thing for testing, I should be able to create one.

Kunda1

2018-07-08 15:15

administrator   ~0011500

@stefan.althoefer can you submit a PR to https://github.com/FreeCAD/FreeCAD ?

Kunda1

2018-07-08 15:16

administrator   ~0011501

@yorik care to weigh in on this ?

stefan.althoefer

2018-07-09 21:01

reporter   ~0011508

@Kunda1 regarding PR: Difficult, never did it before ...

Kunda1

2018-07-10 13:59

administrator   ~0011511

@chrisb would you please test and/or make a PR from 0002821:0011498 ?

chrisb

2018-07-12 09:00

developer   ~0011514

I have no idea of IDF and very little of STEP. I see only @vejmarie who can handle this.

Kunda1

2018-09-26 13:55

administrator   ~0011853

@stefan.althoefer I'm having issues applying the patch

patching file Idf.py
patch: **** malformed patch at line 17: if current_section==".PLACEMENT"  and section_counter>1 and fmod(section_counter,2)==0:
Can you rebase it? I'll apply it once you do.

Also if you want to learn some quick and dirty 'git' check-out https://www.freecadweb.org/wiki/Source_code_management

Kunda1

2018-10-17 20:16

administrator   ~0012047

@stefan.althoefer ping

Kunda1

2018-10-17 20:19

administrator   ~0012048

Added forum thread: https://forum.freecadweb.org/viewtopic.php?f=8&t=31627

Kunda1

2018-10-19 13:21

administrator   ~0012067

@stefan.althoefer ping^2

Kunda1

2018-11-05 18:29

administrator   ~0012136

@stefan.althoefer ping

Kunda1

2019-03-03 14:08

administrator   ~0012828

@vejmarie ping

Kunda1

2020-01-06 15:56

administrator   ~0013992

PING

yorik

2022-03-03 13:55

administrator   ~0016511

This ticket has been migrated to GitHub as issue 5676.

Issue History

Date Modified Username Field Change
2016-12-28 11:57 stefan.althoefer New Issue
2016-12-28 11:57 stefan.althoefer File Added: idf.py.patch
2017-01-17 20:43 Kunda1 Note Added: 0007854
2017-01-28 13:25 Kunda1 Note Added: 0008055
2017-01-28 13:26 Kunda1 Tag Attached: #pending
2017-03-23 23:57 Kunda1 Status new => feedback
2017-03-23 23:57 Kunda1 Note Added: 0008693
2017-06-01 19:15 Kunda1 Note Added: 0009246
2017-06-16 15:55 Kunda1 Note Added: 0009415
2017-06-28 22:12 Kunda1 Note Added: 0009586
2017-07-11 20:19 Kunda1 Note Added: 0009719
2017-07-11 20:19 Kunda1 Tag Attached: import
2017-07-11 20:19 Kunda1 Tag Attached: STEP
2017-08-13 16:57 Kunda1 Note Added: 0009916
2017-09-24 19:29 Kunda1 Note Added: 0010173
2017-10-18 12:30 wmayer Status feedback => closed
2017-10-18 12:30 wmayer Resolution open => not fixable
2018-07-06 22:07 stefan.althoefer Status closed => feedback
2018-07-06 22:07 stefan.althoefer Resolution not fixable => reopened
2018-07-06 22:07 stefan.althoefer Note Added: 0011498
2018-07-06 22:14 stefan.althoefer Note Added: 0011499
2018-07-06 22:14 stefan.althoefer Status feedback => new
2018-07-08 15:15 Kunda1 Note Added: 0011500
2018-07-08 15:16 Kunda1 Note Added: 0011501
2018-07-09 21:01 stefan.althoefer Note Added: 0011508
2018-07-10 13:59 Kunda1 Note Added: 0011511
2018-07-12 09:00 chrisb Note Added: 0011514
2018-09-26 13:55 Kunda1 Note Added: 0011853
2018-10-17 20:16 Kunda1 Note Added: 0012047
2018-10-17 20:16 Kunda1 Status new => feedback
2018-10-17 20:17 Kunda1 Description Updated
2018-10-17 20:18 Kunda1 Additional Information Updated
2018-10-17 20:19 Kunda1 Note Added: 0012048
2018-10-17 20:19 Kunda1 Target Version => 0.18
2018-10-19 13:21 Kunda1 Note Added: 0012067
2018-11-05 18:29 Kunda1 Note Added: 0012136
2019-02-23 20:35 wmayer Target Version 0.18 => 0.19
2019-03-03 14:08 Kunda1 Note Added: 0012828
2020-01-06 15:56 Kunda1 Note Added: 0013992
2021-02-06 06:49 abdullah Target Version => 0.20