|
how to get the name of the reference plane
we know, to create a feature in solidworks we have to select a plane first, then we have to draw a sketch. can i write a macro to get the name of the reference plane on which the sketch used for the feature was created? i got a macro by which i can get the reference planes selected. but i want the name of the reference plane ( whether it is top plane, front plane or right plane).
thank you very much.
hi sonju,
having a sketch object in hand you can use the sketch:: getreferenceentity function that returns the plane (or face) that the sketch was drawn on. having the reference plane you can then use the .name function to get the name.
cheers,
--stav.
in this world i am nobody...
and nobody is perfect ;) !!!
---------
solidworks office 2008 sp4.0
dell precision pws390
nvidia quadro fx 3450/4000 sdi
edited: 07/11/2008 at 04:01 am by stavros antoniou
hi stavros,
thank you very much. by using the .name function i can get the name of the plane on which the first feature is created. but if i select the 2nd or third feature, it shows an error message. how can i get the name of the plane/faces for the 2nd or third faces?
regards
sonju
hi sonju,
what do you mean the second and third features?
can you copy your code here and indicate where the error is thrown?
that will make things alot easier.
cheers,
--stav.
in this world i am nobody...
and nobody is perfect ;) !!!
---------
solidworks office 2008 sp4.0
dell precision pws390
nvidia quadro fx 3450/4000 sdi
hi stav,
here is the code. it shows the name of the plane when i select the first sketch in the sw model. but i want to get the name of the faces/ planes for the later sketches, although we do not select any plane ( we select face) for the later sketches.
thank you very much.
regards
sonju
option explicit
sub main()
dim pswapp as sldworks.sldworks
dim pmodel as sldworks.modeldoc2
dim pselmgr as sldworks.selectionmgr
dim pfeat as sldworks.feature
dim psketch as sldworks.sketch
dim pentity as sldworks.entity
dim nenttype as long
dim nameplane as string
set pswapp = createobject("sldworks.application")
set pmodel = pswapp.activedoc
set pselmgr = pmodel.selectionmanager
set pfeat = pselmgr.getselectedobject5(1)
set psketch = pfeat.getspecificfeature2
set pentity = psketch.getreferenceentity(nenttype)
nameplane = pentity.name
msgbox nameplane
end sub
i am a bit confused here sonju,
the code you attached will work on the first selection you make.
what do you mean when you say:
but i want to get the name of the faces/ planes for the later sketches
do you make more selections of faces and want to get the plane they are created on? bear in mind taht not all faces will have a plane they were created on... the underlying sketch used to create the feaure that the face belongs to will have a plane that was sketched on.
please clarify a bit more on what you are trying to do and i'll see what i can do then.
cheers,
--stav.
in this world i am nobody...
and nobody is perfect ;) !!!
---------
solidworks office 2008 sp4.0
dell precision pws390
nvidia quadro fx 3450/4000 sdi
to aid in your conversation. i created a macro do so something very similar. my "error reporting" method, however, is very crude.
charles culp, cswp
aerospace design engineer
essex industries - st louis, missouri
sw2009 sp2.1
hi stav,
you are right. not for all faces we select a plane they are created on. we select plane only for the first sketch. for the later sketches we need to select faces.
my question is, can i get the name of the plane which the face belongs to.
suppose, i want to extrude a rectangle. so, first of all i select a plane (
hi sonju,
the sketch:: getreferenceentity returns the following:
output: (long) lentitytype
entity type as defined in swselecttype_e (only swselfaces and swseldatumplanes are valid values for this method)
output: (lpdispatch) retval
pointer to the entity dispatch object; this is either a reference plane or a face
in the case that the return value is a reference plane the lentitytype will have the value 4 and in that case you can use the .name function to get the name of the plane.
in the case tha the return value is a face lentitytype will have the value of 2 and in that case you cannot use the .name function as it is not supported by faces.
now having a face in hand i dont think you can get its name (but dont quote me on this one as i am not positive).
what you can do to differentiate between the two is check the return value you already get in your code (nenttype) then you can compare it to swselecttype_e.swselfaces and
swselecttype_e.swseldatumplanes
if it is essentail that you get the name of the plane that the feature was created on you will have to make sure that all your sketches are drawn on planes instead of faces (look into creating reference planes maybe?).
hope this helps,
--stav.
in this world i am nobody...
and nobody is perfect ;) !!!
---------
solidworks office 2008 sp4.0
dell precision pws390
nvidia quadro fx 3450/4000 sdi
hi stav,
thank you very much. by checking the return value of ientitytype i can get whether it is plane or face. but, can i differentiate between the faces somehow? actually, i can the make the faces selected in the sw model. but, it will not work since i want to extract the information using the macro and use it in some other places. can you suggest how i can do it.
regards
sonju
hi sonju,
i would sugest instead of creating the sketch(es) on faces try to do it instead on planes or create your own reference planes. that way you can quarantee that all the sketches are drawn on planes and the macro to extract the planes will work.
hope this helps
--stav.
in this world i am nobody...
and nobody is perfect ;) !!!
---------
solidworks office 2008 sp4.0
dell precision pws390
nvidia quadro fx 3450/4000 sdi |
|