automatic techdraw from STEP files

Need help, or want to share a macro? Post here!
bestfit
Posts: 7
Joined: Wed Oct 10, 2018 5:37 pm

automatic techdraw from STEP files

Postby bestfit » Wed Oct 10, 2018 8:08 pm

Hello,

For my job, I need to open Step Files and extract view of the different compnent and to put dimensions on a 2 D drawing. I'm not enthousiastic to do that a lot of time ... So I tried to automatize that with FC and the macro ... trying first with the macro recorder but it didn't help me a lot... I've found some codes and try to adapt.. but my knowledge of Python is not good enough to understand what append's and how to solve the issues.

1) my way of thinking was the following:
* to access to the file and to keep only the parts ( removing aaxis and plans)
* to techdraw one plan / component with with 3 vues
2) 2 issues:
*for the first drawing it's OK , but for the second one the drawing and the block are not together...
*as yu can constat the file name is hard coded in the program... how to proceed to have a polyvalent macro?
thank's for your help and of course if you need more information don't hesitate to ask...

bestfit
Attachments
POIGNEE.odt
(161.78 KiB) Downloaded 11 times
User avatar
NormandC
Posts: 17276
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: automatic techdraw from STEP files

Postby NormandC » Thu Oct 11, 2018 4:45 am

Hello bestfit,

Welcome.

Come on man, pasting a screenshot into a LibreOffice Write document? And rotated 90 degrees too. :?

Would you please go to the "Help on using FreeCAD" forum and look at the large red/pink banner at the top that says "IMPORTANT: Please read and click here first, before asking for help", in point Nº 5 there is a link to how to create a screen capture on Windows and save it as an image that can be attached directly so it can be visible in the forum.

Thank you.
bestfit
Posts: 7
Joined: Wed Oct 10, 2018 5:37 pm

Re: automatic techdraw from STEP files

Postby bestfit » Thu Oct 11, 2018 7:28 am

Hello NormandC,

Sorry for that; I didn't see it... So You'll find attachedthe document.

Since yesterday, i have modified a little bit the program because I've found something else; I use the "part.feature" and that way I din't have to remove other objects...Doing that , I think I've solved one of my issues

But the other one have not been removed... Why what I've copied for the firts part does'nt work for the other ... I've read the error msg but ..;

I'm enterly conscious that i'm a little bit like a person who believe he can achieve the Himalaya climbing without any training and without equipment.
So I will easely undertsand if you don't want to reply me directly... you certainly have better to do...My concern is to find a solution to that problem and others which will come. I've seen a lot of topics on Freecad macros but It's not very easy and I need someone to put me the foot in the door
Thank you for your help
Best regards
bestfit

for obj in FreeCAD.ActiveDocument.Objects:

#for each part, techdraw 1 drawing with 3 views
page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage','page')
page.Label=obj.Label
FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate','Template')
FreeCAD.ActiveDocument.Template.Template = 'C:/Program Files/FreeCAD 0.17/data/Mod/TechDraw/Templates/A3_Landscape_ISO7200TD.svg'
FreeCAD.ActiveDocument.page.Template = FreeCAD.ActiveDocument.Template
page.ViewObject.show()

#first view
view = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewPart','View')
rc = page.addView(view)

FreeCAD.ActiveDocument.View.Source = [App.ActiveDocument.Part__Feature]

FreeCAD.ActiveDocument.View.Direction = (0.0,1.0,0.0)
FreeCAD.ActiveDocument.View.Scale = (0.5)
FreeCAD.ActiveDocument.View.X = 225
FreeCAD.ActiveDocument.View.Y =150.0

#second view
view2 = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewPart','View2')
rc2 = page.addView(view2)

FreeCAD.ActiveDocument.View2.Source = [App.ActiveDocument.Part__Feature]
FreeCAD.ActiveDocument.View2.Direction = (1.0,0.0,0.0)
FreeCAD.ActiveDocument.View2.Scale = (0.5)
FreeCAD.ActiveDocument.View2.X = (350)
FreeCAD.ActiveDocument.View2.Y = (150)

# third view
view3 = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewPart','View3')
rc3 = page.addView(view3)
FreeCAD.ActiveDocument.View3.Source = [App.ActiveDocument.Part__Feature]
FreeCAD.ActiveDocument.View3.Direction = (-1.0,0.0,0.0)
FreeCAD.ActiveDocument.View3.Scale = (0.5)
FreeCAD.ActiveDocument.View3.X = 100
FreeCAD.ActiveDocument.View3.Y = 150
Attachments
bestfit01.PNG
bestfit01.PNG (138.97 KiB) Viewed 123 times
wandererfan
Posts: 2104
Joined: Tue Nov 06, 2012 5:42 pm

Re: automatic techdraw from STEP files

Postby wandererfan » Thu Oct 11, 2018 2:16 pm

bestfit wrote:
Thu Oct 11, 2018 7:28 am
But the other one have not been removed... Why what I've copied for the firts part does'nt work for the other ... I've read the error msg but ..;
1) use <code></code> tags. It makes it much easier to read the code.

2) try this version. You have variable names and objects mixed together.

Code: Select all

#bestfit.py
templateFile = App.getResourceDir() + "Mod/TechDraw/Templates/A3_Landscape_ISO7200TD.svg"
for obj in FreeCAD.ActiveDocument.Objects:
    #for each part, techdraw 1 drawing with 3 views
    page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage','page')
    page.Label=obj.Label
    
    template = FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate','Template')
    template.Template = templateFile
    page.Template = template
    page.ViewObject.show()

    featName = obj.Name
    feat = FreeCAD.ActiveDocument.getObject(featName)

    #first view
    view = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewPart','View')
    rc = page.addView(view)

    view.Source = [feat]
    view.Direction = (0.0,1.0,0.0)
    view.Scale = (0.5)
    view.X = 225
    view.Y =150.0

    #second view
    view2 = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewPart','View2')
    rc2 = page.addView(view2)

    view2.Source = [feat]
    view2.Direction = (1.0,0.0,0.0)
    view2.Scale = (0.5)
    view2.X = (350)
    view2.Y = (150)

    #third view
    view3 = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewPart','View3')
    rc3 = page.addView(view3)

    view3.Source = [feat]
    view3.Direction = (-1.0,0.0,0.0)
    view3.Scale = (0.5)
    view3.X = 100
    view3.Y = 150
bestfit
Posts: 7
Joined: Wed Oct 10, 2018 5:37 pm

Re: automatic techdraw from STEP files

Postby bestfit » Thu Oct 11, 2018 3:24 pm

:D :D :D
Hi Wandererfan

I've dreamed about it and you've made it ! It work's fine and I could continue on my project; Thank you very much for your help... not sure that I could get the top of the Himalaya but thanks to you , I'm leaving Katmandou.... where I was stuck for a long time... ( see my other msg if not clear)

For the next future, for the code ... I would like to comply your request but I don't know exactly how to proceed...And do I have to close the point?

Once again thank's a lot

Best regards
bestfit