SketchObjectPython - no addGeometry addConstraints setDriving...?

Need help, or want to share a macro? Post here!
paullee
Posts: 1587
Joined: Wed May 04, 2016 3:58 pm

SketchObjectPython - no addGeometry addConstraints setDriving...?

Postby paullee » Sun Jan 14, 2018 8:09 pm

Hi, I search through wiki and forum hours after hours trying to figure out how SketchObjectPython works but in vain.

At first attempt, it just works like sketch object and can edit and add lines, constraints etc.

But, it seems I can't work it like sketch object e.g. .addgeometry .addConstraints .setDriving... etc.
(also can't find seteditormode in earlier post)

I think I have misunderstood some fundamentals...?

Code: Select all

# Sketcher Python Object 
import FreeCAD, FreeCADGui, Sketcher
App = FreeCAD
Gui = FreeCADGui

class SketchFeature:					# class SketcherClass: in wmayer's example
  def __init__(self, obj):
      obj.addProperty("App::PropertyLinkList","Sketches","Sketches","Master Sketches")
      obj.Proxy = self
  def execute(self, fp):
      FreeCAD.Console.PrintMessage("Execute completed before recompute ")
      fp.recompute()					# when used inside the execute() method of a custom feature class it invokes the method of the C++ base class
  def onChanged(self, fp, prop):
      '''Do something when a property has changed'''
      FreeCAD.Console.PrintMessage("Change property: " + str(prop) + "\n")
#  def __setstate__(self, state):
  def __setstate__(self, res):
#      self.object.setEditorMode("MapMode",1)	# Not OK
#      self.Object.setEditorMode("MapMode",1)	# Not OK
#      self.setEditorMode("Constraints",2)	# Not OK
      return None

Code: Select all

s=App.ActiveDocument.addObject("Sketcher::SketchObjectPython")
skf=SketchFeatureTemplate.SketchFeature(s)
s.ViewObject.Proxy=0
Whilst with a sketch named 'sketch' typing "sketch." would return .addgeomtry .addConstraints .ConstraintsCount ...etc. screen capture-1

Typing s. return nothing above...see screen capture-2.

Thanks for any hints!
Screenshot from 2018-01-15 03-55-31.png
Screenshot from 2018-01-15 03-55-31.png (220.04 KiB) Viewed 499 times
Screenshot from 2018-01-15 04-05-57.png
Screenshot from 2018-01-15 04-05-57.png (233.53 KiB) Viewed 499 times
[EDIT]
As it is possibly a bug:-
OS: Linux
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.12920 (Git)
Build type: None
Branch: master
Hash: 8faa9f38bb70a598afc2bc39ea1645d416ab057e
Python version: 2.7.6
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 7.1.0
Locale: English/UnitedStates (en_US)
Last edited by paullee on Sun Jan 14, 2018 11:56 pm, edited 1 time in total.
User avatar
DeepSOIC
Posts: 6639
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: SketchObjectPython - no addGeometry addConstraints setDriving...?

Postby DeepSOIC » Sun Jan 14, 2018 8:22 pm

Hi!
There appears to be a problem, that some methods are invisible if an object has extensions. I've seen missing methods on something else, and they are still there and callable, just not exposed by dir() or the autocomplete. Could you file a bug report?

Code: Select all

>>> s.addGeometry
<built-in method addGeometry of FeaturePython object at 0x00000221555615E8>
paullee
Posts: 1587
Joined: Wed May 04, 2016 3:58 pm

Re: SketchObjectPython - no addGeometry addConstraints setDriving...?

Postby paullee » Sun Jan 14, 2018 11:52 pm

DeepSOIC wrote:
Sun Jan 14, 2018 8:22 pm
Hi!
There appears to be a problem, that some methods are invisible if an object has extensions. I've seen missing methods on something else, and they are still there and callable, just not exposed by dir() or the autocomplete. Could you file a bug report?

Code: Select all

>>> s.addGeometry
<built-in method addGeometry of FeaturePython object at 0x00000221555615E8>
Oh! Totally unexpected! Report in Sketcher right?


BTW, where could I find more documentation e.g. on fp, state, self <-- I haven' found what do they exactly mean afterall!
paullee
Posts: 1587
Joined: Wed May 04, 2016 3:58 pm

Re: SketchObjectPython - no addGeometry addConstraints setDriving...?

Postby paullee » Mon Jan 15, 2018 12:11 am

issue #3311 bug reported.
User avatar
Kunda1
Posts: 4755
Joined: Thu Jan 05, 2017 9:03 pm

Re: SketchObjectPython - no addGeometry addConstraints setDriving...?

Postby Kunda1 » Wed Feb 21, 2018 3:22 pm

DeepSOIC wrote:poke
Is this similar case of dir() not exposing correctly: https://forum.freecadweb.org/viewtopic.php?f=10&t=26907 - missing delConstraint method in python console
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
paullee
Posts: 1587
Joined: Wed May 04, 2016 3:58 pm

Re: SketchObjectPython - no addGeometry addConstraints setDriving...?

Postby paullee » Wed Feb 21, 2018 6:30 pm

Noticed that post - just thought it was SketchObjectPython's problem not Sketcher.