Macro Z values of the flat surfaces

Macro Z values of the flat surfaces

lopezerik73
Contributor Contributor
1,627 Views
16 Replies
Message 1 of 17

Macro Z values of the flat surfaces

lopezerik73
Contributor
Contributor

Hello.

 

As title says i want to make a macro for get the Z values of the flat surfaces.

For the moment only have the flat surfaces selected.

Some one can help me to continue ,please?

Many thanks.

 

kind regards.

Macro:

EDIT MODEL ALL SELECT FLAT 

 

0 Likes
Accepted solutions (3)
1,628 Views
16 Replies
Replies (16)
Message 2 of 17

jean-baptiste.bannerot
Alumni
Alumni
Accepted solution

Hello @lopezerik73,

You want to get the Z values in an external file?

Please try to use the macro in attachment file and say me if it's working as you want.

 

Regards



Jean-Baptiste BANNEROT

Technical consultant

0 Likes
Message 3 of 17

lopezerik73
Contributor
Contributor

Hello @jean-baptiste.bannerot.

 

First at all thanks for answer.

About get the data in external file is not necesary at all.

But , i have a problem, when execute the macro i have error in line 24 : EDIT MODEL ALL SELECT $Surf.

Don´t know what is the problem.

Many thanks for ty to help me.

 

Kind regards.

 

 

0 Likes
Message 4 of 17

jean-baptiste.bannerot
Alumni
Alumni
Please can you send me a screen shot of the error box ?


Jean-Baptiste BANNEROT

Technical consultant

0 Likes
Message 5 of 17

lopezerik73
Contributor
Contributor

Sorry, now i test in other part file and works fine. Smiley Surprised 

Thanks.

Is posible to sort this values  min to max?

Many thanks and sorry.

 

kind regards.

 

Z_Values.JPG

0 Likes
Message 6 of 17

jean-baptiste.bannerot
Alumni
Alumni

Ok perfect.

 

Yes you can find in the documentation all macro function : "C:\Program Files\Autodesk\<PowerMill version>\lib\locale\C\HELP\Pmill.chm".

You can use extract all value from a list. Be carrefull, the macro used a string list and to extract value you need to use a real list.



Jean-Baptiste BANNEROT

Technical consultant

0 Likes
Message 7 of 17

lopezerik73
Contributor
Contributor

Ok, many thanks.

I think for the moment i use it as you do, because i haven´t enough knowledge for the moment to modify.

Many thanks again.

 

Kind regards.

 

0 Likes
Message 8 of 17

Mikhail_Voronin
Advocate
Advocate

Hi Jean-Baptiste,

I have a little problem with the macro

2018-04-27_09-56-17.png

 

________________________________________
Mikhail
0 Likes
Message 9 of 17

jean-baptiste.bannerot
Alumni
Alumni
Hi Mikhail,
Ok what is the problem ? How can I help you ?


Jean-Baptiste BANNEROT

Technical consultant

0 Likes
Message 10 of 17

Mikhail_Voronin
Advocate
Advocate

If PowerMILL doesn't have an English interface the macro doesn't work

 

________________________________________
Mikhail
0 Likes
Message 11 of 17

Accepted solution

Ok I've find the problem.

Please try with this new version of the macro.

Jean-Baptiste



Jean-Baptiste BANNEROT

Technical consultant

Message 12 of 17

Mikhail_Voronin
Advocate
Advocate

It works fine,

Thank you!

 

________________________________________
Mikhail
0 Likes
Message 13 of 17

jean-baptiste.bannerot
Alumni
Alumni

@Mikhail_Voronin don't forget to approve the solution;)

Thanks



Jean-Baptiste BANNEROT

Technical consultant

Message 14 of 17

kandennti
Mentor
Mentor

Even in non-English interface, it should work.
It is also fast.

function main() {
	//Please set a temporary file path
	string tracepath = 'c:\tmp\sel_surfs.txt'
	
	EDIT MODEL ALL DESELECT ALL
	EDIT MODEL ALL SELECT FLAT
	
	string list surfs = {}
	call GetFlatFacesName($tracepath, $surfs)
	if size($surfs) < 1 {
		message warn 'Horizontal plane can not be found!'
		return
	}

	string list zlevel = {}
	call GetZLevelList($surfs, $zlevel)
	
	string $msg = 'Flat surfaces Z value :' + crlf + join(zlevel, crlf)
	message info $msg
}

//高さリスト取得
function GetZLevelList(string list surfs, output string list out) {
	$out = {}
	
	UNDRAW BLOCK
	EDIT BLOCKTYPE BOX
	EDIT BLOCK COORDINATE WORKPLANE
	EDIT PAR powermill.Options.Block.UseReferenceModel 0
	
	EDIT BLOCK ALL UNLOCK
	EDIT BLOCK TOLERANCE '0.01'
	EDIT BLOCK RESETLIMIT '0'
	EDIT BLOCK LIMITTYPE MODEL
	
	string list pros = {}
	int dmy = 0
	string face = ''
	GRAPHICS LOCK
	foreach s in $surfs {
		EDIT MODEL ALL DESELECT ALL
		$face = RTRIM($s)
		EDIT MODEL ALL SELECT $face
		
		EDIT BLOCK RESET
		$dmy = add_last($out, string(round($Block.Limits.ZMin,3)))
	}
	GRAPHICS UNLOCK
	EDIT MODEL ALL DESELECT ALL
	
	$dmy = remove_duplicates($out )
	$out = reverse(sort($out ))
}

//水平面名取得
function GetFlatFacesName(string tracepath, output string list out) {
	$out = {}
	
	ECHO OFF DCPDEBUG UNTRACE COMMAND ACCEPT
	tracefile open $tracepath
	print SELSURFACE
	tracefile close
	ECHO ON DCPDEBUG TRACE COMMAND ACCEPT
	
	file open $tracepath for read as 's'
	file read $out  from 's'
	file close 's'
	delete file $tracepath

	int dmy = remove_first($out )
}
Message 15 of 17

jelrod
Advocate
Advocate

I think I'm getting the same error @lopezerik73 was. Please see attached. Using version 2018

macro_error.png

0 Likes
Message 16 of 17

5axes
Advisor
Advisor
Accepted solution

Nice solution @kandennti

I would just change in your code the location of the temporary tracefile into   :  

	// Temporary file path
	STRING $TraceFilePath = MACRO_PATH(false) + "\Tracefile.txt"

like that you are not dependent of the configuration of your post with a hard coded path.   GetFlatFacesName  could be write like that :

FUNCTION GetFlatFacesName(OUTPUT STRING LIST Surf) {

	// Temporary file path
	STRING $TraceFilePath = MACRO_PATH(false) + "\Tracefile.txt"
	
	$Surf = {}
	
	ECHO OFF DCPDEBUG UNTRACE COMMAND ACCEPT
	TRACEFILE OPEN $TraceFilePath
	PRINT SELSURFACE
	TRACEFILE CLOSE
	ECHO ON DCPDEBUG TRACE COMMAND ACCEPT
	
	FILE OPEN $TraceFilePath FOR READ AS Input
	FILE READ $Surf FROM Input
	FILE CLOSE Input
	DELETE FILE $TraceFilePath

	INT Ret = REMOVE_FIRST($Surf)
}

herewith same macro with block reset 

Message 17 of 17

kandennti
Mentor
Mentor