Jump to content
Ultimaker Community of 3D Printing Experts

Cura Plugin - getPickedPosition


Cuq
 Share

Recommended Posts

Posted · Cura Plugin - getPickedPosition

Hello,

 

Still working on my plugins, I'm wondering if it's possible to get the normal orientation on a picked position ?

 

Best regards,

 

Cuq 

  • Link to post
    Share on other sites

    Posted · Cura Plugin - getPickedPosition

    Yeah, that should be possible. It's not entirely there already, but you can have a look at the lay flat in the rotation tool. That allows you to pick faces already.

    • Thanks 1
    Link to post
    Share on other sites

    Posted · Cura Plugin - getPickedPosition

    Ok I will investigate this code ...

     

        def _onSelectedFaceChanged(self):
            if not self._select_face_mode:
                return
    
            self._handle.setEnabled(not Selection.getFaceSelectMode())
    
            selected_face = Selection.getSelectedFace()
            if not Selection.getSelectedFace() or not (Selection.hasSelection() and Selection.getFaceSelectMode()):
                return
    
            original_node, face_id = selected_face
            meshdata = original_node.getMeshDataTransformed()
            if not meshdata or face_id < 0:
                return
            if face_id > (meshdata.getVertexCount() / 3 if not meshdata.hasIndices() else meshdata.getFaceCount()):
                return
    
            face_mid, face_normal = meshdata.getFacePlane(face_id)
            object_mid = original_node.getBoundingBox().center
            rotation_point_vector = Vector(object_mid.x, object_mid.y, face_mid[2])
            face_normal_vector = Vector(face_normal[0], face_normal[1], face_normal[2])
            rotation_quaternion = Quaternion.rotationTo(face_normal_vector.normalized(), Vector(0.0, -1.0, 0.0))
    
            operation = GroupedOperation()
            current_node = None  # type: Optional[SceneNode]
            for node in Selection.getAllSelectedObjects():
                current_node = node
                parent_node = current_node.getParent()
                while parent_node and parent_node.callDecoration("isGroup"):
                    current_node = parent_node
                    parent_node = current_node.getParent()
            if current_node is None:
                return
    
            rotate_operation = RotateOperation(current_node, rotation_quaternion, rotation_point_vector)
            operation.addOperation(rotate_operation)
            operation.push()

     

    • Like 1
    Link to post
    Share on other sites

    Posted · Cura Plugin - getPickedPosition

    I'm still avaing some problem to implement this code .  I can get the facette center point and the normal with 

     

    face_mid, face_normal = meshdata.getFacePlane(face_id)

     

    But I'm still fighting with the possibility to have in the same time the subroutine _onSelectedFaceChanged and def event(self, event)  . An idea or a suggestion to move forward on this point ?

     

  • Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     Share

    • Our picks

      • The Ultimaker Showcase — October 14. What's new?
        Your dear friends at Ultimaker have some exciting news and insights for you!
         
        • 0 replies
      • New here? Get ahead with a free onboarding course
        Hi,
         
        Often getting started is the most difficult part of any process. A good start sets you up for success and saves you time and energy that could be spent elsewhere. That is why we have a onboarding course ready for
        Ultimaker S5 Pro Bundle, Ultimaker S5, Ultimaker S3 Ultimaker 2+ Connect.   
        They're ready for you on the Ultimaker Academy platform. All you need to do to gain access is to register your product to gain free access. 
        Ready? Register your product here in just 60 seconds.
          • Like
        • 8 replies
    ×
    ×
    • Create New...