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: 

Move model to multiple workplanes macro

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
iamcdn79
492 Views, 5 Replies

Move model to multiple workplanes macro

I have an existing macro that I want to change to move the model to multiple workplane locations instead of just one that I currently have. 

 

This macro works if I just select one workplane but if I select more than one it errors on line 

ACTIVATE WORKPLANE $wp.Name
 
This is what I have currently

 

STRING yourworkplanename = "G54","G55","G56","G57","G58","G59"
IF ENTITY_EXISTS('workplane', $yourworkplanename) {
//Do Nothing
	} ELSE {
		GRAPHICS LOCK
      // 	CREATE WORKPLANE AT G54
MODE WORKPLANE_CREATE "G54" INTERACTIVE POINT
MODE COORDINPUT COORDINATES -6.0493 -14.5758 0
	
		// CREATE WORKPLANE AT G55
MODE WORKPLANE_CREATE "G55" INTERACTIVE POINT
MODE COORDINPUT COORDINATES -6.0493 -6.7024 0
 //CREATE WORKPLANE AT G56
MODE WORKPLANE_CREATE "G56" INTERACTIVE POINT
MODE COORDINPUT COORDINATES -15.8944 -14.5758 0

//CREATE WORKPLANE AT G57
MODE WORKPLANE_CREATE "G57" INTERACTIVE POINT
MODE COORDINPUT COORDINATES -15.8944 -6.7024 0

//CREATE WORKPLANE AT G58
MODE WORKPLANE_CREATE "G58" INTERACTIVE POINT
MODE COORDINPUT COORDINATES -25.3346 -12.3245 0

//CREATE WORKPLANE AT G59
MODE WORKPLANE_CREATE "G59" INTERACTIVE POINT
MODE COORDINPUT COORDINATES -25.3346 -7.4026 0

UNDRAW WORKPLANE ALL

GRAPHICS UNLOCK
    }
/ ENTITY LIST
ENTITY LIST $Model = INPUT ENTITY MODEL "Select Which Model To Copy To Fixture Offset"

STRING $Newmodel = new_entity_name('model')
STRING $folderFull = "Model\" + $Model.Name

// Allow selection of multiple workplanes
ENTITY LIST $wpNames = INPUT ENTITY MULTIPLE WORKPLANE "Select The Fixture Offsets To Move The Model To"

FOREACH wp IN $wpNames {
  // Activate current workplane
  ACTIVATE WORKPLANE $wp.Name <----- THIS LINE ERRORS ON ME WHEN NEEDING TO ACTIVATE SECOND SELECTED WORKPLANE FROM INPUT LIST

  // Store workplane name for later use
  STRING $currentWpName = $wp.Name 


  IF NOT folder_exists($folderFull) {
    CREATE FOLDER "Model" $Model.Name
  }
  ACTIVATE FOLDER $folderFull

  EDIT MODEL $Model.Name CLIPBOARD COPY
  CREATE MODEL CLIPBOARD
  TRANSFORM TYPE WORKPLANE TRANSFORM MODEL $Newmodel
  DEACTIVATE WORKPLANE

  // Unique naming based on model and workplane
  STRING $newName = $Model.Name + "_" + $currentWpName
  INT $i = 1
  WHILE ENTITY_EXISTS('model', $newName) {
    $newName = $newName + "_" + $i
    $i = $i + 1
  }
  RENAME MODEL $Newmodel $newName

  EDIT MODEL $newName SELECT ALL

  // Check if "Moved" level exists
 IF NOT ENTITY_EXISTS('level',"Moved Models to Fixture Offset") {
   CREATE LEVEL "Moved Models to Fixture Offset" Level
}
 EDIT LEVEL "Moved Models to Fixture Offset" ACQUIRE SELECTED
 DEACTIVATE FOLDER $folderFull
}
QUIT

 

 

iamcdn79_0-1718277360511.png

 


Intel Core i9 13900KF CPU
128 GB Kingston Beast DDR4 SDRAM
PNY RTX A2000 6GB Video Card
WD 1 TB SSD Hard Drive
Windows 11 Pro

5 REPLIES 5
Message 2 of 6
icse
in reply to: iamcdn79

i currently dont have a powermill licence so i can't debug your code...

 

This lines confuses me, it looks like you try to create a list of string but the LIST keyword is missing so do the {}.

In your state the IF statement probably only checks the if the G54 Workplane exists(i guess the yourworkplane variable is just "G54")

STRING yourworkplanename = "G54","G55","G56","G57","G58","G59"
IF ENTITY_EXISTS('workplane', $yourworkplanename) {

 

next this,

first line misses one /

second got the list keyword but on the right side the MULTIPLE keyword is missing.

/ ENTITY LIST
ENTITY LIST $Model = INPUT ENTITY MODEL "Select Which Model To Copy To Fixture Offset"

 

for the line that errors you you could try to set the wp.Name into {} like this:

ACTIVATE WORKPLANE ${wp.Name}

 

hope this helps, can't do more atm sorry.

Message 3 of 6
iamcdn79
in reply to: icse

1) Ok good catch, made the necessary change to 

 

 

STRING LIST yourworkplanenames = {"G54","G55","G56","G57","G58","G59"}

FOREACH wpname IN yourworkplanenames {
  IF ENTITY_EXISTS('workplane', $wpname) {
// ... rest of code ...
  }
}

 

 

2) I missed highlighting the second / in the code

I only want to select one model instead of multiple 

 

3) 

 

ACTIVATE WORKPLANE ${wp.Name}

 

also errors when activating the second workplane

 

iamcdn79_0-1718314390320.png

 


Intel Core i9 13900KF CPU
128 GB Kingston Beast DDR4 SDRAM
PNY RTX A2000 6GB Video Card
WD 1 TB SSD Hard Drive
Windows 11 Pro

Message 4 of 6
Sean571
in reply to: iamcdn79

Hmm I know it's not the syntax that is causing an error like this as a simplified foreach loop will work just fine if this is all that is in a macro:

 

// Allow selection of multiple workplanes
ENTITY LIST $wpNames = INPUT ENTITY MULTIPLE WORKPLANE "Select The Fixture Offsets To Move The Model To"

FOREACH wp IN $wpNames {
    // Activate current workplane
    ACTIVATE WORKPLANE $wp.Name
    message info $wp.Name
    deactivate workplane
}

 


So the only thing I that comes to mind is that something in your foreach loop is putting PowerMill into some type of error state or a state in which Activating a workplane isn't allowed. Might be similar to what happens when you try to save your project when you are in the curve editor. You'd get this error:

Sean571_0-1718391600116.png



Can you repost the entire macro with all the changes you made, so I can test with what you have right now?

Otherwise I'd be curious if you got the same error if you replaced your foreach loop with this loop instead-keeping all the other commands above it.

 

FOREACH wp IN $wpNames {
    // Activate current workplane
    ACTIVATE WORKPLANE $wp.Name
    message info $wp.Name
    deactivate workplane
}

 


If you still get an error then we know that it's being caused by something that you are doing in the previous lines in the macro. If you don't get an error then we know that the issues is to do with something in the foreach loop.

Sean Wroblewski
Applications Engineer


Message 5 of 6
iamcdn79
in reply to: Sean571

So I don't know what happened but this works for me now unless I had a messed up line that I didn't change after using @icse recommendation

 

 

STRING LIST yourworkplanenames = {"G54","G55","G56","G57","G58","G59"}

FOREACH wpname IN yourworkplanenames {
  IF ENTITY_EXISTS('workplane', $wpname) {
//Do Nothing
	} ELSE {
		GRAPHICS LOCK
      // 	CREATE WORKPLANE AT G54
MODE WORKPLANE_CREATE "G54" INTERACTIVE POINT
MODE COORDINPUT COORDINATES -6.0493 -14.5758 0
	
		// CREATE WORKPLANE AT G55
MODE WORKPLANE_CREATE "G55" INTERACTIVE POINT
MODE COORDINPUT COORDINATES -6.0493 -6.7024 0
 //CREATE WORKPLANE AT G56
MODE WORKPLANE_CREATE "G56" INTERACTIVE POINT
MODE COORDINPUT COORDINATES -15.8944 -14.5758 0

//CREATE WORKPLANE AT G57
MODE WORKPLANE_CREATE "G57" INTERACTIVE POINT
MODE COORDINPUT COORDINATES -15.8944 -6.7024 0

//CREATE WORKPLANE AT G58
MODE WORKPLANE_CREATE "G58" INTERACTIVE POINT
MODE COORDINPUT COORDINATES -25.3346 -12.3245 0

//CREATE WORKPLANE AT G59
MODE WORKPLANE_CREATE "G59" INTERACTIVE POINT
MODE COORDINPUT COORDINATES -25.3346 -7.4026 0

UNDRAW WORKPLANE ALL

GRAPHICS UNLOCK
    }
}

// ENTITY LIST
ENTITY LIST $Model = INPUT ENTITY MODEL "Select Which Model To Copy To Fixture Offset"

STRING $Newmodel = new_entity_name('model')
STRING $folderFull = "Model\" + $Model.Name

// Allow selection of multiple workplanes
ENTITY LIST $wpNames = INPUT ENTITY MULTIPLE WORKPLANE "Select The Fixture Offsets To Move The Model To"

FOREACH wp IN $wpNames {
  // Activate current workplane
  ACTIVATE WORKPLANE ${wp.Name}

  // Store workplane name for later use
  STRING $currentWpName = $wp.Name


  IF NOT folder_exists($folderFull) {
    CREATE FOLDER "Model" $Model.Name
  }
  ACTIVATE FOLDER $folderFull

  EDIT MODEL $Model.Name CLIPBOARD COPY
  CREATE MODEL CLIPBOARD
  TRANSFORM TYPE WORKPLANE TRANSFORM MODEL $Newmodel
  DEACTIVATE WORKPLANE

  // Unique naming based on model and workplane
  STRING $newName = $Model.Name + "_" + $currentWpName
  INT $i = 1
  WHILE ENTITY_EXISTS('model', $newName) {
    $newName = $newName + "_" + $i
    $i = $i + 1
  }
  RENAME MODEL $Newmodel $newName

  EDIT MODEL $newName SELECT ALL

  // Check if "Moved" level exists
 IF NOT ENTITY_EXISTS('level',"Moved Models to Fixture Offset") {
   CREATE LEVEL "Moved Models to Fixture Offset" Level
}
}
EDIT LEVEL "Moved Models to Fixture Offset" ACQUIRE SELECTED
EDIT MODEL ALL DESELECT ALL

DEACTIVATE FOLDER $folderFull

QUIT
DEACTIVATE WORKPLANE $wpName
QUIT

 

 


Intel Core i9 13900KF CPU
128 GB Kingston Beast DDR4 SDRAM
PNY RTX A2000 6GB Video Card
WD 1 TB SSD Hard Drive
Windows 11 Pro

Message 6 of 6
icse
in reply to: iamcdn79

Sometimes powermill get stuck/behaves strange after you got some errors while debugging. 

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report