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: 

featureset creation without chemfer

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
karan30782
317 Views, 4 Replies

featureset creation without chemfer

HI ! Everyone,

 

Can anyone help me with the following macro.

Everytime when I run the macro it stops with an error.

 

17.JPG

 

 

FUNCTION Main () {

FORM BLOCK
EDIT BLOCK RESET
BLOCK ACCEPT
EDIT MODEL ALL SELECT SURFACE
EDIT FEATURECREATE TYPE HOLE EDIT FEATURECREATE CIRCULAR ON EDIT FEATURECREATE FILTER HOLES EDIT FEATURECREATE TOPDEFINE ABSOLUTE EDIT FEATURECREATE BOTTOMDEFINE ABSOLUTE FORM CANCEL FEATURE FORM CREATEHOLE
EDIT OPTIONS CLOSETOL "0.01"
EDIT FEATURECREATE HOLES FIXED ON
EDIT FEATURECREATE HOLES COMPOUND OFF
EDIT FEATURECREATE HOLES DIRECTION DOWN
EDIT FEATURECREATE MULTAX OFF
EDIT FEATURECREATE HOLES OPEN ON
EDIT FEATURECREATE MIN_ARC_ANGLE "175"
EDIT FEATURECREATE HOLES CAPPED EXCLUDE
EDIT FEATURECREATE CREATEHOLES
FORM CANCEL CREATEHOLE







STRING $fset = INPUT ENTITY FEATURESET "Select FeatureSet"
CALL RemoveChamfers($fset)


FUNCTION RemoveChamfers (STRING CurrentFeatureset) {
// Removes Chamfers from holes, and extends the next featureset depth.
INT subNum = 0
INT comp = 0
INT TestUnsorted = 0
BOOL RemovedChamfer = 0
STRING ActiveFS = $CurrentFeatureset
STRING NEWActiveFS = $ActiveFS + "_NO_CHAMFERS"
STRING NEXTActiveFS = ""
STRING $Testing = 0


IF entity_exists('FEATURESET',$NEWActiveFS) {
	DELETE FEATURESET $NEWActiveFS
}

DEACTIVATE FEATURESET
Activate FeatureSet $ActiveFS
$NEXTActiveFS = new_entity_name('FEATURESET',$ActiveFS)
COPY FEATURESET $ActiveFS
RENAME Featureset $NEXTActiveFS $NEWActiveFS
Activate FeatureSet $NEWActiveFS
INT SSubIndex = 0


	FOREACH feat IN components (ENTITY ('Featureset',$NEWActiveFS)) {
		IF feat.type == 'hole' {
			$SSubIndex = 0
			IF feat.num_items > 1 {
				FOREACH sub IN components(feat) {
					$SSubIndex = $SSubIndex + 1
					IF ((sub.Draft < 50) AND (sub.Draft > 40)) OR ((sub.Draft > -50) AND (sub.Draft < -40)) {
						IF $SSubIndex < 2 {   
							$RemovedChamfer = 1
							INT subNum2 = $subNum + 1
							REAL depthPrevComp = 0
							ACTIVATE FEATURESET $NEWActiveFS
							EDIT FEATURESET $NEWActiveFS SELECT $feat.name
							IF subNum > 0 {
								$depthPrevComp = abs(components(components(entity('Featureset', $NEWActiveFS))[$comp])[$subNum-1].Depth)
							}	
							IF subNum2 < feat.num_items {
								REAL depth = abs(components(components(entity('Featureset', $NEWActiveFS))[$comp])[$subNum2].Depth) - $depthPrevComp
								EDIT FEATURESET ; FEATURE SELECTION $subNum2
								EDIT FEATURESET ; FEATURE SELECTED COMPONENT SELECTED DEPTH $depth
							} 
							IF subNum2 == feat.num_items {
								$subNum2 = $subNum2 - $subNum
								REAL depth = 0
								IF feat.num_items > 2 {
									$depth = abs(components(components(entity('Featureset', $NEWActiveFS))[$comp])[$subNum].Depth) - abs(components(components(entity('Featureset', $NEWActiveFS))[$comp])[0].Depth)
								} ELSE {
									$subNum2 = $subNum2 - 1
									$depth = abs(components(components(entity('Featureset', $NEWActiveFS))[$comp])[$subNum].Depth)
								}	
								EDIT FEATURESET ; FEATURE SELECTION $subNum2
								EDIT FEATURESET ; FEATURE SELECTED COMPONENT SELECTED DEPTH $depth
								}	
							EDIT FEATURESET ; FEATURE SELECTION $subNum
							EDIT FEATURESET ; FEATURE DELETE
							EDIT FEATURESET $NEWActiveFS DESELECT $feat.name
							$subNum = $subNum - 1
						}
					}
					$subNum = $subNum + 1
				}
				$subNum = 0
			}
		}
		$comp = $comp + 1
			$Testing = "Feature Dia = "+$feat.Diameter
			PRINT $Testing
	}
	$comp = 0
	// Delete the Featureset if NO chamfers were found.
$TestUnsorted = POSITION($NEWActiveFS,"UNSORTED")
	IF $RemovedChamfer == 0 {
		DELETE FEATURESET $NEWActiveFS
	} ELSEIF $TestUnsorted == -1 {
		CALL RenameHoleFS($NEWActiveFS)
		}
	}


FUNCTION RenameHoleFS(STRING CWP) {
// Renames Featureset to add non-chamger diameter

	STRING WPN = workplane.name
	STRING MessageString = ""
	STRING TempString = ""
	
	INT FIndex = 0
	INT StringStart = LENGTH($WPN) + 1
	INT StringEnd = POSITION($CWP,"_NO_CHAMFERS") 
	INT StringLen = $StringEnd - $StringStart
	$TempString = SUBSTRING($CWP, $StringStart, $StringLen)
	PRINT $TempString
	REAL FirstDia = REAL($TempString)
	PRINT $FirstDia
	REAL NewDia = 0
	
	//FIND OLD DIAMETER
	
	
	FOREACH f IN COMPONENTS(ENTITY('featureset',$CWP)) {
		$FIndex = $FIndex + 1
		IF f.type == "hole" {
			//$MessageString = "New Hole DIAMETER: "+STRING($f.DIAMETER)
			
			$NewDia = f.diameter
			//PRINT $MessageString
		}
	}
STRING TempName = "("+STRING($NewDia)+")_"+$TempString
STRING NewName = REPLACE($CWP, $TempString, $TempName)

RENAME Featureset $CWP $NewName

}



DELETE FEATURESET "1"
}

 

 

Thank to who help !

 

4 REPLIES 4
Message 2 of 5
ondrej.mikulec
in reply to: karan30782

The ending on the line 151 and 152 needs to be moved into lines 27 and 28 so the main function block will be closed before the other sub-functions codes.

Message 3 of 5
icse
in reply to: karan30782

i added the missing {

 

also the last command (delete featureset "1") looks like out of place

 

FUNCTION Main () {

	FORM BLOCK
	EDIT BLOCK RESET
	BLOCK ACCEPT
	EDIT MODEL ALL SELECT SURFACE
	EDIT FEATURECREATE TYPE HOLE EDIT FEATURECREATE CIRCULAR ON EDIT FEATURECREATE FILTER HOLES EDIT FEATURECREATE TOPDEFINE ABSOLUTE EDIT FEATURECREATE BOTTOMDEFINE ABSOLUTE FORM CANCEL FEATURE FORM CREATEHOLE
	EDIT OPTIONS CLOSETOL "0.01"
	EDIT FEATURECREATE HOLES FIXED ON
	EDIT FEATURECREATE HOLES COMPOUND OFF
	EDIT FEATURECREATE HOLES DIRECTION DOWN
	EDIT FEATURECREATE MULTAX OFF
	EDIT FEATURECREATE HOLES OPEN ON
	EDIT FEATURECREATE MIN_ARC_ANGLE "175"
	EDIT FEATURECREATE HOLES CAPPED EXCLUDE
	EDIT FEATURECREATE CREATEHOLES
	FORM CANCEL CREATEHOLE
	
	STRING $fset = INPUT ENTITY FEATURESET "Select FeatureSet"
	CALL RemoveChamfers($fset)
}


FUNCTION RemoveChamfers (STRING CurrentFeatureset) {
	// Removes Chamfers from holes, and extends the next featureset depth.
	INT subNum = 0
	INT comp = 0
	INT TestUnsorted = 0
	BOOL RemovedChamfer = 0
	STRING ActiveFS = $CurrentFeatureset
	STRING NEWActiveFS = $ActiveFS + "_NO_CHAMFERS"
	STRING NEXTActiveFS = ""
	STRING $Testing = 0
	
	
	IF entity_exists('FEATURESET',$NEWActiveFS) {
		DELETE FEATURESET $NEWActiveFS
	}

	DEACTIVATE FEATURESET
	Activate FeatureSet $ActiveFS
	$NEXTActiveFS = new_entity_name('FEATURESET',$ActiveFS)
	COPY FEATURESET $ActiveFS
	RENAME Featureset $NEXTActiveFS $NEWActiveFS
	Activate FeatureSet $NEWActiveFS
	INT SSubIndex = 0


	FOREACH feat IN components (ENTITY ('Featureset',$NEWActiveFS)) {
		IF feat.type == 'hole' {
			$SSubIndex = 0
			IF feat.num_items > 1 {
				FOREACH sub IN components(feat) {
					$SSubIndex = $SSubIndex + 1
					IF ((sub.Draft < 50) AND (sub.Draft > 40)) OR ((sub.Draft > -50) AND (sub.Draft < -40)) {
						IF $SSubIndex < 2 {   
							$RemovedChamfer = 1
							INT subNum2 = $subNum + 1
							REAL depthPrevComp = 0
							ACTIVATE FEATURESET $NEWActiveFS
							EDIT FEATURESET $NEWActiveFS SELECT $feat.name
							IF subNum > 0 {
								$depthPrevComp = abs(components(components(entity('Featureset', $NEWActiveFS))[$comp])[$subNum-1].Depth)
							}	
							IF subNum2 < feat.num_items {
								REAL depth = abs(components(components(entity('Featureset', $NEWActiveFS))[$comp])[$subNum2].Depth) - $depthPrevComp
								EDIT FEATURESET ; FEATURE SELECTION $subNum2
								EDIT FEATURESET ; FEATURE SELECTED COMPONENT SELECTED DEPTH $depth
							} 
							IF subNum2 == feat.num_items {
								$subNum2 = $subNum2 - $subNum
								REAL depth = 0
								IF feat.num_items > 2 {
									$depth = abs(components(components(entity('Featureset', $NEWActiveFS))[$comp])[$subNum].Depth) - abs(components(components(entity('Featureset', $NEWActiveFS))[$comp])[0].Depth)
								} ELSE {
									$subNum2 = $subNum2 - 1
									$depth = abs(components(components(entity('Featureset', $NEWActiveFS))[$comp])[$subNum].Depth)
								}	
								EDIT FEATURESET ; FEATURE SELECTION $subNum2
								EDIT FEATURESET ; FEATURE SELECTED COMPONENT SELECTED DEPTH $depth
								}	
							EDIT FEATURESET ; FEATURE SELECTION $subNum
							EDIT FEATURESET ; FEATURE DELETE
							EDIT FEATURESET $NEWActiveFS DESELECT $feat.name
							$subNum = $subNum - 1
						}
					}
					$subNum = $subNum + 1
				}
				$subNum = 0
			}
		}
		$comp = $comp + 1
		$Testing = "Feature Dia = "+$feat.Diameter
		PRINT $Testing
	}
	$comp = 0
	// Delete the Featureset if NO chamfers were found.
	$TestUnsorted = POSITION($NEWActiveFS,"UNSORTED")
	IF $RemovedChamfer == 0 {
		DELETE FEATURESET $NEWActiveFS
	} ELSEIF $TestUnsorted == -1 {
		CALL RenameHoleFS($NEWActiveFS)
	}
}


FUNCTION RenameHoleFS(STRING CWP) {
// Renames Featureset to add non-chamger diameter

	STRING WPN = workplane.name
	STRING MessageString = ""
	STRING TempString = ""
	
	INT FIndex = 0
	INT StringStart = LENGTH($WPN) + 1
	INT StringEnd = POSITION($CWP,"_NO_CHAMFERS") 
	INT StringLen = $StringEnd - $StringStart
	$TempString = SUBSTRING($CWP, $StringStart, $StringLen)
	PRINT $TempString
	REAL FirstDia = REAL($TempString)
	PRINT $FirstDia
	REAL NewDia = 0
	
	//FIND OLD DIAMETER
	
	
	FOREACH f IN COMPONENTS(ENTITY('featureset',$CWP)) {
		$FIndex = $FIndex + 1
		IF f.type == "hole" {
			//$MessageString = "New Hole DIAMETER: "+STRING($f.DIAMETER)
			
			$NewDia = f.diameter
			//PRINT $MessageString
		}
	}
	STRING TempName = "("+STRING($NewDia)+")_"+$TempString
	STRING NewName = REPLACE($CWP, $TempString, $TempName)

	RENAME Featureset $CWP $NewName

}
Message 4 of 5
karan30782
in reply to: icse

Thanks my friend.

Message 5 of 5
karan30782
in reply to: karan30782

Hi !

 

But, My issue isn't resolved.

This macro create hole with chamfer only, but it was intended to eleminate all chemfers.

It created hole with chemfer like this....

 

9.jpg

 

I need like this

 

10.jpg

 

Thank you !!

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report