Python subclass of PartDesign::Subtractive?

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
jrheinlaender
Posts: 554
Joined: Sat Apr 07, 2012 2:42 am

Python subclass of PartDesign::Subtractive?

Postby jrheinlaender » Tue Jan 08, 2013 3:34 pm

Hi,

I create a Hole feature (see viewtopic.php?f=9&t=3413) in Python.

In order to make this work with patterns, it needs to be a subclass of PartDesign::Additive. Is this possible? How?

Thanks,
Jan
logari81
Posts: 654
Joined: Mon Jun 14, 2010 6:00 pm

Re: Python subclass of PartDesign::Subtractive?

Postby logari81 » Tue Jan 08, 2013 5:23 pm

shouldn't it just be SketchBased (: Additive || Subtractive) instead?
wmayer
Site Admin
Posts: 15966
Joined: Thu Feb 19, 2009 10:32 am

Re: Python subclass of PartDesign::Subtractive?

Postby wmayer » Tue Jan 08, 2013 8:04 pm

Creating such a sub-class is pretty simple. To the header file add such a line after the class definition of Subtractive:

Code: Select all

typedef App::FeaturePythonT<Subtractive> SubtractivePython;
At the end of the cpp file add a block like this:

Code: Select all

namespace App {
  /// @cond DOXERR
  PROPERTY_SOURCE_TEMPLATE(PartDesign::SubtractivePython, PartDesign::Subtractive)
  template<> const char* PartDesign::SubtractivePython::getViewProviderName(void) const {
    return "PartDesignGui::ViewProviderSubtractivePython";
  }
  /// @endcond
  // explicit template instantiation
  template class PartDesignExport FeaturePythonT<PartDesign::Subtractive>;
}
Add to file AppPartDesign.cpp this line:

Code: Select all

PartDesign::SubtractivePython::init();
Usually you do the same for the view provider class. But at the moment there is no class ViewProviderSubtractive. So, you can make a typedef to the the nearest view provider class in the descent:

Code: Select all

typedef Gui::ViewProviderPythonFeatureT<PartGui::ViewProviderPart> ViewProviderSubtractivePython;

Code: Select all

namespace Gui {
/// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(PartDesignGui::ViewProviderSubtractivePython, PartGui::ViewProviderPart)
/// @endcond

// explicit template instantiation
template class PartDesignGuiExport ViewProviderPythonFeatureT<PartGui::ViewProviderPart>;
}

Code: Select all

PartDesignGui::ViewProviderSubtractivePython::init();
logari81
Posts: 654
Joined: Mon Jun 14, 2010 6:00 pm

Re: Python subclass of PartDesign::Subtractive?

Postby logari81 » Tue Jan 08, 2013 9:26 pm

I hadn't noticed that none of the PartDesign features are interfaced in python. In this case you need to implement the missing python for SubtractiveFeature.

However, you need this only because your Hole implementation is based on boolean cut instead of the Groove feature. In the future, when the Groove feature supports arbitrary sketch planes it would be nice to rewrite the Hole feature based on the Groove feature.
User avatar
jriegel
Site Admin
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Python subclass of PartDesign::Subtractive?

Postby jriegel » Wed Jan 09, 2013 1:53 pm

Yes we do the exposure not automatically. You need it only for the key classes. The rest would only pollute the name-space...
But for the PartDesign key features its necessary!
Maybe we should do that even for the 0.13. Its not very invasive....
Stop whining - start coding!
jrheinlaender
Posts: 554
Joined: Sat Apr 07, 2012 2:42 am

Re: Python subclass of PartDesign::Subtractive?

Postby jrheinlaender » Thu Jan 10, 2013 4:20 pm

In the future, when the Groove feature supports arbitrary sketch planes it would be nice to rewrite the Hole feature based on the Groove feature.
I think I will just wait for the future. For the time being, the Hole feature simply won't work with Patterns. Shouldn't be a problem on the development branch, I think.
mk2
Posts: 77
Joined: Wed Dec 10, 2014 4:27 pm

Re: Python subclass of PartDesign::Subtractive?

Postby mk2 » Mon Dec 15, 2014 3:57 pm

Hello,

I think a Bore-Tool will be really usefull in the Part / PartDesign WB. Is there somebody which want to develope a Bore-Tool, maybe with the code from jrheinlaender? I could make a file with many standard bore-dimensions. In the moment i can't code something, because im too new in Python and FreeCAD, but i will learn :)


Kind Regards

mk2
eivindkvedalen
Posts: 602
Joined: Tue Jan 29, 2013 10:35 pm

Re: Python subclass of PartDesign::Subtractive?

Postby eivindkvedalen » Mon Dec 15, 2014 8:40 pm

mk2 wrote:I think a Bore-Tool will be really usefull in the Part / PartDesign WB. Is there somebody which want to develope a Bore-Tool, maybe with the code from jrheinlaender? I could make a file with many standard bore-dimensions. In the moment i can't code something, because im too new in Python and FreeCAD, but i will learn :)
Hi,

I've already started on such a feature (viewtopic.php?f=17&t=4423) some time ago, but I won't work more on it until I have the Spreadsheet workbench finished.

Best regards,
Eivind