Community
PowerMill Forum
Welcome to Autodesk’s PowerMill Forums. Share your knowledge, ask questions, and explore popular PowerMill topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Multiple Entity Export Macro

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
evo80
276 Views, 5 Replies

Multiple Entity Export Macro

Hi @icse,

I'd like to add models to the Export macro but I get an error at line 146, could you help?

Appreciated!

So I deleted the rogue }

Well spotted by the way!

And this now fires ok.

I now get all sorts of errors from the Import macro??

But it does run through and import the entities.

 

bool $query = 0
$query = query "Import Entities?"
if not $query {
	return
}

string $path = "C:/Temp/EntityExport"

if not dir_exists($path) {
	message warn "Project not found"
	macro abort
}

if length(project_pathname(0)) == 0 OR project_modified() == 1 {
	
	bool $save = 0
	$save = query 'Save?'
	
	if $save {
		project save
	} else { 
		macro abort
	}
}

PROJECT IMPORT PROJSELECTOR $path

 

5 REPLIES 5
Message 2 of 6
evo80
in reply to: evo80

Ok,

Simply turned ERRORS OFF.

Hmmm, that just brings in an empty model. 

Message 3 of 6
icse
in reply to: evo80

There was another error not only the missing {

 

I think you also need to copy the .pmlmz file

 

if length(project_pathname(0)) == 0 OR project_modified() == 1 {
	message warn 'Save First'
	return
}

string $path = "C:/Temp/EntityExport"

if dir_exists($path) {
	bool $query = 0
	$query = query "Replace existing Entities?"
	if $query {
		delete directory $path
	} else {
		return
	}
}
string list $inputTypes = {'toolpath','tool','boundary','pattern','featureset','workplane','model'}
int list $indexer = input choice multiple $inputTypes 'Choose Type of Entity to Export'


entity list $entitiesToExport = {}

foreach $index in $indexer {
	
	entity list $entities = {}
	
	SWITCH $index {	
		Case 0
			$entities = input entity multiple toolpath 'Select Toolpaths to Export'
			Break
		Case 1
			$entities = input entity multiple tool 'Select Tools to Export'
			Break
		Case 2
			$entities = input entity multiple boundary 'Select Boundaries to Export'
			Break
		Case 3
			$entities = input entity multiple pattern 'Select Patterns to Export'
			Break
		Case 4
			$entities = input entity multiple featureset 'Select Featuresets to Export'
			Break
		Case 5
			$entities = input entity multiple workplane 'Select Workplanes to Export'
			Break
		Case 6
			$entities = input entity multiple model 'Select Models to Export'
			Break
		DEFAULT
			return
			BREAK
		}		
	foreach $ent in $entities {
		int $i = add_last($entitiesToExport, $ent)
	}
}


mkdir $path

//Active entity file
string $activeEntityFilePath = $path + '/active_entity.pmldat'
string $op = '0 1 # Active Entities (DO NOT EDIT!)'

if file_exists($activeEntityFilePath) {
	delete File $activeEntityFilePath
}
file open $activeEntityFilePath for write as output
file write $op to output
file close output

int $entCount = 0
string $content = ''
foreach $e in $entitiesToExport {

	if entity_exists($e) {	
		
		if $e.RootType == 'toolpath' {
		
			string $eHash = "x" + $e.ID + ".pmlent"
			string $e_full = project_pathname(0) + "/" + $eHash
			string $path_full = $path + "/" + $eHash
			if not file_exists($path_full) {
				$entCount = $entCount + 1
				$content = $content + $eHash + " pmlEntToolpath '" + $e.Name + "'" + CRLF
			}
			copy file $e_full $path_full
		
			$eHash = "x" + $e.ID + ".pmlgeom"
			$e_full = project_pathname(0) + "/" + $eHash
			$path_full = $path + "/" + $eHash
			copy file $e_full $path_full
			
			if entity_exists($e.Boundary) {
				$eHash = "x" + $e.Boundary.ID + ".pmlent"
				$e_full = project_pathname(0) + "/" + $eHash
				$path_full = $path + "/" + $eHash
				if not file_exists($path_full) {
					$entCount = $entCount + 1
					$content = $content + $eHash + " pmlEntBoundary '" + $e.Boundary.Name + "'" + CRLF
				}				
				copy file $e_full $path_full
			}
			if entity_exists($e.Pattern) {
				$eHash = "x" + $e.Pattern.ID + ".pmlent"
				$e_full = project_pathname(0) + "/" + $eHash
				$path_full = $path + "/" + $eHash
				if not file_exists($path_full) {
					$entCount = $entCount + 1
					$content = $content + $eHash + " pmlEntPattern '" + $e.Pattern.Name + "'" + CRLF
				}
				copy file $e_full $path_full
			}
			if entity_exists($e.Tool) {
				$eHash = "x" + $e.Tool.ID + ".pmlent"
				$e_full = project_pathname(0) + "/" + $eHash
				$path_full = $path + "/" + $eHash
				if not file_exists($path_full) {
					$entCount = $entCount + 1
					$content = $content + $eHash + " pmlEntTool '" + $e.Tool.Name + "'" + CRLF
				}
				copy file $e_full $path_full
			}
			if entity_exists($e.Workplane) {
				$eHash = "x" + $e.Workplane.ID + ".pmlent"
				$e_full = project_pathname(0) + "/" + $eHash
				$path_full = $path + "/" + $eHash
				if not file_exists($path_full) {
					$entCount = $entCount + 1
					$content = $content + $eHash + " pmlEntWorkplane '" + $e.Workplane.Name + "'" + CRLF
				}
				copy file $e_full $path_full
			}
			if entity_exists($e.Featureset) {
				$eHash = "x" + $e.Featureset.ID + ".pmlent"
				$e_full = project_pathname(0) + "/" + $eHash
				$path_full = $path + "/" + $eHash
				if not file_exists($path_full) {
					$entCount = $entCount + 1
					$content = $content + $eHash + " pmlEntFeature '" + $e.Featureset.Name + "'" + CRLF
				}
				copy file $e_full $path_full
			}			
			if entity_exists($e.Model) {
				$eHash = "x" + $e.Model.ID + ".pmlent"
				$e_full = project_pathname(0) + "/" + $eHash
				$path_full = $path + "/" + $eHash
				if not file_exists($path_full) {
					$entCount = $entCount + 1
					$content = $content + $eHash + " pmlEntModel '" + $e.Model.Name + "'" + CRLF
				}
				copy file $e_full $path_full
			}
			continue
		}					
		if $e.RootType == 'boundary' {
			string $eHash = "x" + $e.Boundary.ID + ".pmlent"
			string $e_full = project_pathname(0) + "/" + $eHash
			string $path_full = $path + "/" + $eHash
			if not file_exists($path_full) {
				$entCount = $entCount + 1
				$content = $content + $eHash + " pmlEntBoundary '" + $e.Name + "'" + CRLF
			}				
			copy file $e_full $path_full
			continue
		}
		if $e.RootType == 'pattern' {
			string $eHash = "x" + $e.Pattern.ID + ".pmlent"
			string $e_full = project_pathname(0) + "/" + $eHash
			string $path_full = $path + "/" + $eHash
			if not file_exists($path_full) {
				$entCount = $entCount + 1
				$content = $content + $eHash + " pmlEntPattern '" + $e.Name + "'" + CRLF
			}
			copy file $e_full $path_full
			continue
		}
		if $e.RootType == 'tool' {
			string $eHash = "x" + $e.Tool.ID + ".pmlent"
			string $e_full = project_pathname(0) + "/" + $eHash
			string $path_full = $path + "/" + $eHash
			if not file_exists($path_full) {
				$entCount = $entCount + 1
				$content = $content + $eHash + " pmlEntTool '" + $e.Name + "'" + CRLF
			}
			copy file $e_full $path_full
			continue
		}
		if $e.RootType == 'workplane' {
			string $eHash = "x" + $e.Workplane.ID + ".pmlent"
			string $e_full = project_pathname(0) + "/" + $eHash
			string $path_full = $path + "/" + $eHash
			if not file_exists($path_full) {
				$entCount = $entCount + 1
				$content = $content + $eHash + " pmlEntWorkplane '" + $e.Name + "'" + CRLF
			}
			copy file $e_full $path_full
			continue
		}
		if $e.RootType == 'featureset' {
			string $eHash = "x" + $e.Featureset.ID + ".pmlent"
			string $e_full = project_pathname(0) + "/" + $eHash
			string $path_full = $path + "/" + $eHash
			if not file_exists($path_full) {
				$entCount = $entCount + 1
				$content = $content + $eHash + " pmlEntFeature '" + $e.Name + "'" + CRLF
			}
			copy file $e_full $path_full
			continue
		}
		if $e.RootType == 'model' {
			string $eHash = "x" + $e.model.ID + ".pmlent"
			string $e_full = project_pathname(0) + "/" + $eHash
			string $path_full = $path + "/" + $eHash
			if not file_exists($path_full) {
				$entCount = $entCount + 1
				$content = $content + $eHash + " pmlEntModel '" + $e.Name + "'" + CRLF
			}
			copy file $e_full $path_full
			
			$eHash = "x" + $e.model.ID + ".pmlmz"
			$e_full = project_pathname(0) + "/" + $eHash
			$path_full = $path + "/" + $eHash
			
			copy file $e_full $path_full
			
			continue
		}
		
	}
}


if file_exists($activeEntityFilePath) {
	delete File $activeEntityFilePath
}
file open $activeEntityFilePath for write as output
file write $op to output
file close output




string $proj_name = "\" + project_pathname(1) + ".pmlprj"
string $path_full = project_pathname(0) + $proj_name
file open $path_full for read as input

string $line1 = ''
string $line2 = ''
string $line3 = ''

file read $line1 from input
file read $line2 from input
file read $line3 from input

file close input

$line1 = $entCount + substring($line1, position($line1, ' ', 0), length($line1))
string $dest_path_full = $path + $proj_name
file open $dest_path_full FOR WRITE AS output
file write $line1 to "output"
file write $line2 to "output"
file write $line3 to "output"
file write $content to "output"
file close output
Message 4 of 6
evo80
in reply to: icse

Cheers,

That works a treat.

Just a question, why do models need that .pmlmz file to work? 

Message 5 of 6
icse
in reply to: evo80

I dont know why,

toolpath's also need an additional file (.pmlgeom)

 

 

Message 6 of 6
evo80
in reply to: icse

Yes, I noticed that ext. was different to the others.

Thanks for the help once again!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators