View Full Version : How to select a face in Lisp?
Michel Gendron
03-02-2004, 12:41 PM
Hi,
We are working on an excel spreadsheet to generate a 3D model. On that model we need to add threaded holes. The machining option ask me to specify a face and a point on that face.
How can I select a face without using the viewport selection?
Selecting it using a feature name sound easy, but to define a feature, you must select the face! So I got the same problem!
I know than the point 1,1,0 is on that face
Can anyone help me?
John van Doorn
03-02-2004, 03:36 PM
Hi,
see example code below:
(setf p1 (make-gpnt3d :x 1.0 :y 1.0 :z 0.0))
(setf cil_face
(sd-call-cmds
(get_selection
:focus_type *sd-cylinder-seltype*
:check_function
#'(lambda (this-face)
(if (setf proj_pnt (sd-proj-pnt-on-face this-face p1 :source-space :global))
:ok
:filter
)
)
:select
:in_part partname)))
dorothea
03-02-2004, 11:01 PM
Hi,
You can also pass the point directly to the select function.
(setf point 1.0,1.0,0.0)
(setf face
(sd-call-cmds
(get_selection
focus_type *sd-face-seltype*
:select :selected_part <the part sel item>
point)))
The parameter :selected_part is necessary to make the selection unique. If there are 2 faces of different parts at the same position you will not know which face is returned.
The point can also be a variable.
Dorothea
Harry
08-24-2004, 02:23 AM
I wanted to make a generic funtion to get a face by a point and a part. However the result I get back from the function is always nil.
Can anyone give me a hint what I am overlooking?
(sd-defdialog 'get_face_test
:dialog-title "tst"
:variables
'(
(UI_PART
:value-type :part-incl-new
:modifies :contents
:title "Part"
:prompt-text "SELECT PART..."
)
(UI_CP
:value-type :point-3d
:title "CenterPoint"
:prompt-text "PICK A POINT ON FACE..."
)
);variables
:ok-action '(DISPLAY (sd-face-p
(get_face_part_pnt :part UI_PART :POINT UI_CP) )
)
);defdialog
(defun get_face_part_pnt(&key PART POINT)
;function: get face by the part containing the face and a 3d point on the face
;date : 23-08-2004
;----------------------------------------------------------------------
;input : :PART [part], part containing face
;output: :POINT [gpnt3d], point on face
(progn
(let (a_face)
(progn
(setf a_face
(sd-call-cmds
(GET_SELECTION
:focus_type *sd-face-seltype*
:select :selected_part PART
POINT) ))
;return code
a_face
);progn
);let
);progn
)
Best regards,
Harry
John van Doorn
08-24-2004, 03:28 AM
hi Harry,
I've changed your ok-action to the following:
:ok-action '(display (sd-face-p (sd-inq-face-geo (first (get_face_part_pnt :part UI_PART :POINT UI_CP)))))
This is what I did:
first of all the selection returnes a list, so with the "first" command you'll receive the first item from that list which will be either nil or a face sel_item.
Secondly sd-face-p needs to have a sd-face structure as a parameter and not a sel_item, this can be achieved by the command sd-inq-face-geo.
Hope this helps,
John
Harry
08-24-2004, 04:43 AM
Originally posted by John van Doorn
hi Harry,
I've changed your ok-action to the following:
:ok-action '(display (sd-face-p (sd-inq-face-geo (first (get_face_part_pnt :part UI_PART :POINT UI_CP)))))
...
Secondly sd-face-p needs to have a sd-face structure as a parameter and not a sel_item, this can be achieved by the command sd-inq-face-geo.
...
Thanks John, your awnser helped me a lot. I got the code working. But to be fair, I don't understand the difference between a face sel_item and a face structure very well.... :(
Greetings Harry
vBulletin® v3.7.4, Copyright ©2000-2008, Jelsoft Enterprises Ltd.