featureset creation without chemfer

featureset creation without chemfer

karan30782
Advocate Advocate
1,019 Views
9 Replies
Message 1 of 10

featureset creation without chemfer

karan30782
Advocate
Advocate

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 !

 

0 Likes
Accepted solutions (1)
1,020 Views
9 Replies
Replies (9)
Message 2 of 10

ondrej.mikulec
Advocate
Advocate

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 10

icse
Collaborator
Collaborator
Accepted solution

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 10

karan30782
Advocate
Advocate

Thanks my friend.

0 Likes
Message 5 of 10

karan30782
Advocate
Advocate

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 !!

0 Likes
Message 6 of 10

karan30782
Advocate
Advocate

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....

0 Likes
Message 7 of 10

huseyin_sahin
Enthusiast
Enthusiast

Hi,

I use  attached macro to delete chamfers from holes.

 

0 Likes
Message 8 of 10

karan30782
Advocate
Advocate

not working

0 Likes
Message 9 of 10

huseyin_sahin
Enthusiast
Enthusiast

Working at my side.

 

 

0 Likes
Message 10 of 10

karan30782
Advocate
Advocate

That's nice ..

Let me try once again.

 

Will let you know if works !

 

 

Thanks again

0 Likes