[ArchWall - PR Merged] Auto-creating ArchSketch

A forum dedicated to the Draft, Arch and BIM workbenches development.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

Re: [ArchWall - PR Submitted] Auto-creating ArchSketch

Post by paullee »

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 :-
  1. The proposed codes would be contained in Arch.py and the original ArchSketchObject.py modules

    Arch.py
  2. The basic class ArchSketchObject is declared
  3. The child class ArchSketch inherits parent class ArchSketchObject here
  4. They are technically existed as 1) Arch.ArchSketch, 2) Arch.ArchSketchObject ?
    (Arch.ArchSketchObject <-- Arch.ArchSketch ?)

    ArchSketchObject.py
  5. The module itself has same name as the parent class ArchSketchObject
  6. The same basic class ArchSketchObject is declared in the module ArchSketchObject.py
    (and likewise for ArchSketch)
  7. In this module, the child class ArchSketch inherit parent class ArchSketchObject
  8. The 2 classes here are technically existed as 1) ArchSketchObject.ArchSketch, 2) ArchSketchObject.ArchSketchObject ?
    (ArchArchSketchObject.ArchSketchObject <-- ArchSketchObject.ArchSketch ?)

The confusion :-

  1. When Arch.py import ArchSketchObject.py, as tested, the module 'ArchSketchObject' seems 'overrides/takeover' the class 'ArchSketchObject'
  2. Not sure if the 'newly imported' ArchSketchObject module would frustrate the originally declared 'ArchSketch' class, which inherit the original 'ArchSketchObject' class
  3. Are those existing ArchSketch created by users before this 're-structuring', were ArchSketchObject.ArchSketch?
  4. So, is the 'new object' is Arch.ArchSketch ? and if this works ?


Sorry for a number of beginner's question :oops:
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

Re: [ArchWall - PR Submitted] Auto-creating ArchSketch

Post by paullee »

Another thought - somewhere in Arch.py still :-

Code: Select all

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 :) )
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

Re: [ArchWall - PR Submitted] Auto-creating ArchSketch

Post by paullee »

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.

Arch - Paul - 2022.10.3_ 1.py
(3.34 KiB) Downloaded 44 times
Arch - Paul - 2022.10.3_ 2.py
(3.25 KiB) Downloaded 46 times
Screenshot from 2022-10-03 00-38-24.png
Screenshot from 2022-10-03 00-38-24.png (248.16 KiB) Viewed 1637 times
Screenshot from 2022-10-03 00-43-43.png
Screenshot from 2022-10-03 00-43-43.png (248.35 KiB) Viewed 1637 times
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

paullee

Post by paullee »

Tested and below seems to be working :) :-
  1. Make a ArchSketchObject.py as below e.g. in Arch folder (same name as the module in the SketchArch external add-on)
  2. Include just the declaration with no actual codes / methods for the features
  3. If the actual SketchArch add-on is not present, this minimal ArchSketch module / definition is loaded
  4. The ArchSketch objects previously created loaded without errors, just without the features it used to have
  5. 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' ? )
Would this works ?

ArchSketchObject.py in Arch folder
ArchSketchObject.py
(258 Bytes) Downloaded 45 times

Code: Select all

class ArchSketchObject:								
    def __init__(self, obj):							
        pass
										
class ArchSketch(ArchSketchObject):						
    def __init__(self, obj):							
        pass
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: [ArchWall - PR Submitted] Auto-creating ArchSketch

Post by yorik »

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:

Code: Select all

myobj = FreeCAD.ActiveDocument.addObject("App::FeaturePython","test")
MyObjectDefinitionClass(myobj)
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
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

Re: [ArchWall - PR Submitted] Auto-creating ArchSketch

Post by paullee »

Tested in 2 environments, in linux only :)
  1. AppImage (0.21_pre) on Fedora 36
  2. FreeCAD (0.20.1) on Fedora36 repo (F36)

Run FreeCAD with 'minimal' ArchSkechObject.py
  1. AppImage: 'Extracted' AppImage into folders
  2. AppImage: Copied the 'minimal' ArchSketchObject.py into the .../Arch folder
  3. FreeCAD on F36 repo : Located the Mod : /usr/lib64/freecad/Mod/Arch
  4. FreeCAD on F36 repo : Copied by sudo the 'minimal' ArchSketchObject.py into the ... /usr/lib64/freecad/Mod/Arch
Result :-
  1. ArchSketch objects loaded without error
  2. Getmodule (from inspect) find the module is that copied into the FreeCAD Mod
    (see screencaptures)

Run FreeCAD with 'Additional External Add-on'
  1. Create a Link to the SketchArch add-on folder, at home directory .../.local/share/FreeCAD/Mod
    (keeping the 'Minimal ArchSketchObject.py')
  2. Then run FreeCAD on F36, or, the AppImage
  3. ArchSketch objects loaded without error; all features are available
  4. Getmodule (from inspect) find the module is that copied into the .../.local/share/FreeCAD/Mod
    (see screencaptures)

Screencaptures
  1. FC (0.20.1) on F36 repo : 'Minimal ArchSketchObject.py'
  2. AppImage (0.21_pre) on F36 : 'Minimal ArchSketchObject.py'
  3. FC (0.20.1) on F36 repo : With External add-on, link at .loca/share/FreeCAD/Mod
    (keeping 'Minimal ArchSketchObject.py')
  4. AppImage (0.21_pre) on F36 : With External add-on, link at .loca/share/FreeCAD/Mod
    (keeping 'Minimal ArchSketchObject.py')
Screenshot from 2022-10-04 20-54-17.png
Screenshot from 2022-10-04 20-54-17.png (254.59 KiB) Viewed 1479 times
Screenshot from 2022-10-04 21-09-49.png
Screenshot from 2022-10-04 21-09-49.png (246.78 KiB) Viewed 1479 times
Screenshot from 2022-10-04 21-07-51.png
Screenshot from 2022-10-04 21-07-51.png (274.31 KiB) Viewed 1479 times
Screenshot from 2022-10-04 21-13-22.png
Screenshot from 2022-10-04 21-13-22.png (296.9 KiB) Viewed 1479 times
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

Re: [ArchWall - PR Submitted] Auto-creating ArchSketch

Post by paullee »

paullee wrote: Tue Oct 04, 2022 1:23 pm Result :-
  1. ArchSketch objects loaded without error
  2. Getmodule (from inspect) find the module is that copied into the FreeCAD Mod
    (see screencaptures)
@yorik, considering adding this 'dump' module in the PR, good to put in the Arch directory or otherwise ?

Thanks.

ArchSketchObject.py
(1.91 KiB) Downloaded 35 times
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: [ArchWall - PR Submitted] Auto-creating ArchSketch

Post by yorik »

paullee wrote: Fri Oct 21, 2022 9:19 am good to put in the Arch directory or otherwise ?
Yes, ATM Arch is a single-directory module, so for now I'd simply put it there...
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

Re: [ArchWall - PR Submitted] Auto-creating ArchSketch

Post by paullee »

User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: [ArchWall - PR Submitted] Auto-creating ArchSketch

Post by Kunda1 »

@yorik if you have a moment, can you take a look at the PR?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Post Reply