Check if a work plane is exist.

Check if a work plane is exist.

peterquRXR7S
Advocate Advocate
1,728 Views
12 Replies
Message 1 of 13

Check if a work plane is exist.

peterquRXR7S
Advocate
Advocate

I need a help. When I use macro to drill a hole, I don't want to make lots of work planes. I want to know if the work plane exists already. If I have this work plane already, activate it.  Thanks!

0 Likes
Accepted solutions (1)
1,729 Views
12 Replies
Replies (12)
Message 2 of 13

urizenYHS3W
Advocate
Advocate

What do you mean?

 

  1. That a particularly named workplane exists?
  2. That the Workplane parameter has been activated?
  3. That a workplane wioth a specific orientation exists?
0 Likes
Message 3 of 13

cfastNJWK6
Advisor
Advisor

If you right click on the featureset and click "Activate Workplane", PowerMILL will activate the workplane that was created when the hole featureset was created.

Macro command to activate the workplane for the active featureset would be:

ACTIVATE WORKPLANE FROMENTITY FEATURESET ;

 

0 Likes
Message 4 of 13

peterquRXR7S
Advocate
Advocate

Thank you for replying. I mean I have many work planes already. One of these work planes( "Datum_A) is the same direction with the hole. I want to use Datum_A drill this hole. I don't want to activate the feature set work plane. Other wise, I will have too many work planes.

0 Likes
Message 5 of 13

peterquRXR7S
Advocate
Advocate
  1. That a particularly named workplane exists?
  2. That the Workplane parameter has been activated?
  3. That a workplane wioth a specific orientation exists?

The work plane may not exist. The X,Y orientation is not important. Just the same Z axis direction is OK. For example, When I drill a hole, I will search if there is a work plane has the same Z axis. If it is true, then use this work plane. If false,  activate the feature set work plane.

0 Likes
Message 6 of 13

cfastNJWK6
Advisor
Advisor

So you are looking for a macro that will activate an already existing workplane, that is aligned with an active featureset?  If there is no workplane in the project, create one aligned to the hole?

0 Likes
Message 7 of 13

peterquRXR7S
Advocate
Advocate

Yes. But I don't have to create one. Powermill creates a work plane for each feature set automatically. I just activate it.

0 Likes
Message 8 of 13

cfastNJWK6
Advisor
Advisor

So...

You just want a macro that will check if there are any other workplanes in the project with the same Z vector as the active workplane?  If there are, present a list for you to select which workplane you would like to use?

0 Likes
Message 9 of 13

peterquRXR7S
Advocate
Advocate

Yes. If there is one only, I can use it directly. 

0 Likes
Message 10 of 13

cfastNJWK6
Advisor
Advisor
Accepted solution

Try this:

STRING $wp = ""
IF entity_exists(Workplane) {
	$wp = $Workplane.Name
	} ELSE {
	MESSAGE INFO "Please activate a Workplane and try again"
	MACRO ABORT
	}
REAL $vector = entity('Workplane', $wp).ZAxis[2]
STRING LIST $WorkPlanes = {}

FOREACH $w IN folder('Workplane') {
	IF $w.Name != $wp  {
		REAL $vec = $w.ZAxis[2]
		IF $vec == $vector {
			int b = add_last($WorkPlanes, $w.Name)
			}
		}
	
	}

IF is_empty($WorkPlanes) {
	MESSAGE INFO "No other workplanes with the same Z vector"
	MACRO ABORT
	} ELSE {
	INT $ActivateWP = INPUT CHOICE $WorkPlanes "These workplanes have the same Z vector. Select one to activate"
	STRING $newWP = $WorkPlanes[$ActivateWP]
	ACTIVATE WORKPLANE $newWP
	}
0 Likes
Message 11 of 13

peterquRXR7S
Advocate
Advocate

Thank you so much! I will test it later.

Message 12 of 13

peterquRXR7S
Advocate
Advocate

I tested it. Sometimes it doesn't work. The feature set has an angle, It still ask me choose an other work plane, which is a straight work plane. 

0 Likes
Message 13 of 13

peterquRXR7S
Advocate
Advocate

STRING $wp = ""
IF entity_exists(Workplane) {
$wp = $Workplane.Name
} ELSE {
MESSAGE INFO "Please activate a Workplane and try again"
MACRO ABORT
}
REAL $vector = entity('Workplane', $wp).ZAxis[0]
REAL $vector1 = entity('Workplane', $wp).ZAxis[1]
REAL $vector2 = entity('Workplane', $wp).ZAxis[2]


STRING LIST $WorkPlanes = {}

FOREACH $w IN folder('Workplane') {
IF $w.Name != $wp {
REAL $vec = $w.ZAxis[0]
REAL $vec1 = $w.ZAxis[1]
REAL $vec2 = $w.ZAxis[2]
IF $vec == $vector and $vec1 == $vector1 and $vec2 == $vector2 {
int b = add_last($WorkPlanes, $w.Name)
}
}

}

IF is_empty($WorkPlanes) {
MESSAGE INFO "No other workplanes with the same Z vector"
MACRO ABORT
} ELSE {
INT $ActivateWP = INPUT CHOICE $WorkPlanes "These workplanes have the same Z vector. Select one to activate"
STRING $newWP = $WorkPlanes[$ActivateWP]
ACTIVATE WORKPLANE $newWP
}

 

I changed your program a little bit and it works good so far. Thank you for your help!