sketchucation logo sketchucation
    • Login
    1. Home
    2. Grays42
    3. Posts
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    G
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 3
    • Posts 21
    • Groups 1

    Posts

    Recent Best Controversial
    • Can't draw subclasses of Sketchup::Edge

      Short version: If I define a class "GcodeEdge < Sketchup::Edge", is there any way to actually draw it?

      Long version: I'm having difficulty writing functions that link and manage Edge objects that act like "gcode", i.e., contain information that allow the edges to be transformed into toolpaths for a CNC machine. In order to function properly, they'd need to link together discretely, and I'm choosing to implement it similar to a doubly linked list, storing coupling information in instance variables.

      Up to this point, I've been simply extending the Edge class itself within a module, but that created a new problem when, upon onEraseEntity(), the entity no longer has access to the methods and variables that allow it to decouple itself from linked GCode edges. The two linked edges have no idea that their shared edge was erased, and I have no way of calling a decouple method on them without reference to the deleted Edge.

      The ideal solution would be to simply make a subclass of Sketchup::Edge that contains all of the extension I need (by overriding .erase!), but a new problem has developed: I can't draw it! The only way to draw edges is with Entities.add_edges, and there's no apparent way to directly draw subclasses. My edges will be perfectly valid as Edges in all respects except for some added functionality, but there's no way to get them into the model.

      The other solution I tried prior to this was to add a class variable to store references to all of the gcode edges and simply have every single gcode edge validate itself and decouple individually in the event that any one gcode edge is deleted. That gets annoyingly complicated, and a subclass would be a much more durable solution.

      I'm stumped; any suggestions?

      posted in Developers' Forum
      G
      Grays42
    • 1
    • 2
    • 2 / 2