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

    MarkBergaas

    @MarkBergaas

    10
    Reputation
    1
    Profile views
    3
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    MarkBergaas Unfollow Follow
    registered-users

    Latest posts made by MarkBergaas

    • RE: New API doc - typos and questions

      Behavior.snapto

      I see two problems with the documentation of this method (I would like to call it a property, but that is probably my C# habit talking):

      The "Returns:" section says it returns true or false, but it actually returns one of the 4 values listed in the description above "Returns:" (the default seems to be SnapTo_Arbitrary). The first sentence of the description ("The snapto method is used to verify the status of a component's "snap to" behavior.") also implies that the return value is a status, not the actual "snap to" selection.

      It would be very helpful if the documentation of this method would make it clear that the value of Behavior.snapto works in conjunction with the value of Behavior.is2d to set the "glue to" behavior. If is2d equals false, the component will not glue to anything, no matter what value snapto returns. If is2d equals true, the component will glue to faces matching the snapto value.

      I don’t think it is at all clear that these two (snapto and is2d) are related. It would be helpful to include a reference to snapto in the description of is2d, also.

      This second issue applies equally, if not more, to the snapto= and is2d= methods.

      posted in Developers' Forum
      M
      MarkBergaas
    • RE: ComponentDefinition.behavior.snapto does not work for me

      I found it! I needed to set behavior.is2d to true, also. Now it works like a charm.

      posted in Developers' Forum
      M
      MarkBergaas
    • ComponentDefinition.behavior.snapto does not work for me

      Hi,

      I am new to Ruby and I am trying to write a script to create a component that will glue to vertical faces and cut an opening. This would be the equivalent of going to the Edit tab in the Components dialog, selecting my component, and setting the "Glue to:" drop down to "Vertical" and checking the "Cut opening" box.

      As far as I can tell from the documentation, what I need to do in the script is set properties on the Behavior object in the ComponentDefinition for my component. I set behavior.cuts_opening to true and behavior.snapto to SnapTo_Vertical.

      When I do this, and then open the Components dialog to view my new component, the "Cut opening" box is checked but the "Glue to:" selection is "None" and, indeed, when I try to glue an instance of my component to a vertical face it does not work. Interesting, though, that if I use puts to inspect the value of the snapto property it is actually 2 (which I believe is the value of SnapTo_Vertical).

      Is there something else I need to do to make these settings effective? I have attached an rb file that demonstrates this problem, and also included the script in the text below:

      Ruby script example

      Code below:

      ` require 'Sketchup'
      def doComponent
      colPoints = [
      Geom::Point3d.new(0, 0, -2),
      Geom::Point3d.new(10, 0, -2),
      Geom::Point3d.new(10, 10, -2),
      Geom::Point3d.new(0, 10, -2) ]

      newFace = Sketchup.active_model.entities.add_face(colPoints[0], colPoints[1], colPoints[2], colPoints[3])

      newFace.pushpull(8, false)
      newGroupEntities = newFace.all_connected

      newGroupEntities.each do |theEntity|
      if theEntity.kind_of?(Sketchup::Face)
      if theEntity.normal == newFace.normal or theEntity.normal == newFace.normal.reverse
      theEntity.material = 0x948B4E
      theEntity.material.alpha = 0.1
      else
      theEntity.material = 0xBDDEE1;
      end
      end
      end

      newGroup = Sketchup.active_model.entities.add_group(newGroupEntities.to_a)

      #add entities for the cut plane
      colPoints.each do |thePoint|
      thePoint.z = 2
      end
      Sketchup.active_model.entities.add_line(colPoints[0], colPoints[1])
      Sketchup.active_model.entities.add_line(colPoints[1], colPoints[2])
      Sketchup.active_model.entities.add_line(colPoints[2], colPoints[3])
      Sketchup.active_model.entities.add_line(colPoints[3], colPoints[0])

      #create the component
      newGroup = Sketchup.active_model.entities.add_group(Sketchup.active_model.entities.to_a)
      newComponent = newGroup.to_component
      newComponent.definition.name = "My Component"
      newDefinition = Sketchup.active_model.definitions[newComponent.definition.name]

      #transform the component's axes so the cut plane entities and the xy axes coincide
      transformation = Geom::Transformation.translation(Geom::Vector3d.new(0, 0, -4))
      newDefinition.entities.transform_entities(transformation, newComponent.definition.entities.to_a)

      #set the component behavior to glue to ("snap to") vertical surfaces and cut an opening
      newDefinition.behavior.snapto = SnapTo_Vertical
      newDefinition.behavior.cuts_opening = true

      puts "newDefinition.behavior.snapto=" + newDefinition.behavior.snapto.to_s
      end

      doComponent`

      posted in Developers' Forum
      M
      MarkBergaas