Thanks, reading the codes again I find it confuse myself; read some python materials and tested with some further codes for a while but still confused (as still a python beginner). Maybe I try describing my confusion here and see if something needs re-structuring
The codes :-
The proposed codes would be contained in Arch.py and the original ArchSketchObject.py modules
Arch.py
The basic class ArchSketchObject is declared
The child class ArchSketch inherits parent class ArchSketchObject here
They are technically existed as 1) Arch.ArchSketch, 2) Arch.ArchSketchObject ?
(Arch.ArchSketchObject <-- Arch.ArchSketch ?)
ArchSketchObject.py
The module itself has same name as the parent class ArchSketchObject
The same basic class ArchSketchObject is declared in the module ArchSketchObject.py
(and likewise for ArchSketch)
In this module, the child class ArchSketch inherit parent class ArchSketchObject
The 2 classes here are technically existed as 1) ArchSketchObject.ArchSketch, 2) ArchSketchObject.ArchSketchObject ?
(ArchArchSketchObject.ArchSketchObject <-- ArchSketchObject.ArchSketch ?)
The confusion :-
When Arch.py import ArchSketchObject.py, as tested, the module 'ArchSketchObject' seems 'overrides/takeover' the class 'ArchSketchObject'
Not sure if the 'newly imported' ArchSketchObject module would frustrate the originally declared 'ArchSketch' class, which inherit the original 'ArchSketchObject' class
Are those existing ArchSketch created by users before this 're-structuring', were ArchSketchObject.ArchSketch?
So, is the 'new object' is Arch.ArchSketch ? and if this works ?
try:
# Loading the external Add-on ArchSketchObject.py module
import ArchSketchObject
except:
FreeCAD.Console.Log(obj.Name+": ArchSketch not found\n")
# No SketchArch add-on present, creating SketchArch classes without content to avoid instance loading failure
class ArchSketchObject:
def __init__(self, obj):
pass
class ArchSketch(ArchSketchObject):
def __init__(self, obj):
pass
Thanks for any comment
EDIT - Regardless if these 2 approaches work or not, another issue, they both There is an issue here, this method try to load the ArchSketchObject.py upon loading Arch.py - loading ArchSketchObject is long as it is monolithic containing about 1800 lines of codes (those not yet exposed contain a few thousand lines )
Tested finally, it seems defining ArchSketch class (/ArchSketchObject class) in Arch.py does not work, reading more online resource about python module
See 2 modified Arch.py and 2 screencaptures below.
Make a ArchSketchObject.py as below e.g. in Arch folder (same name as the module in the SketchArch external add-on)
Include just the declaration with no actual codes / methods for the features
If the actual SketchArch add-on is not present, this minimal ArchSketch module / definition is loaded
The ArchSketch objects previously created loaded without errors, just without the features it used to have
When the external add-on is present, it seems FreeCAD regard that has higher priority, and load the add-on !
(or it actually loaded the external add-on afterwards, so the external add-on 'supercede' the 'built-in' ? )
paullee wrote: ↑Tue Oct 04, 2022 4:54 am
When the external add-on is present, it seems FreeCAD regard that has higher priority, and load the add-on !
(or it actually loaded the external add-on afterwards, so the external add-on 'supercede' the 'built-in' ? )
Are you sure this works? Because normally when you do this:
the module where MyObjectDefinitionClass is defined is also stored. I need to check the Document.xml file, but I think it is. If not, then what you suggests seems like a good idea