Macro Help - Foreach segment in a pattern

Macro Help - Foreach segment in a pattern

jake.montgomery
Enthusiast Enthusiast
1,705 Views
9 Replies
Message 1 of 10

Macro Help - Foreach segment in a pattern

jake.montgomery
Enthusiast
Enthusiast

Hello,

 

Does anyone know how to achieve a foreach loop for segments within a pattern? I am trying to analyze each segment inside one of my patterns and remove the segment if it doesn't meet my criteria. 

 

Thank you all in advance for any assistance

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

kukelyk
Advisor
Advisor
Accepted solution
0 Likes
Message 3 of 10

jake.montgomery
Enthusiast
Enthusiast

Thank you very much! That will work perfectly

0 Likes
Message 4 of 10

robert.reedHH7Q9
Explorer
Explorer

Is there an updated version of this link? I'm trying to do a similar task and believe this might help me out.

0 Likes
Message 5 of 10

kukelyk
Advisor
Advisor

Hi, 

I do not remember what was under the link, but please write what is Your goal.

0 Likes
Message 6 of 10

cfastNJWK6
Advisor
Advisor

This isn't exactly what you were asking for, but here is a macro that I wrote for someone wanting to analyze a pattern to find the smallest rad.  You may be able to take some of the logic here and re-purpose it:

ENTITY $pat = INPUT ENTITY PATTERN "Select the Pattern to Analyze"
DIALOGS MESSAGE OFF
EDIT PATTERN $pat.Name SELECT ALL
EDIT PATTERN $pat.Name SPLIT

INT $Segments = segments($pat)

INT $counter = 0
REAL $rad = 0
EDIT PATTERN $pat.Name CURVEEDITOR START
REAL $SmallestArc = 9999999

WHILE $counter < $Segments {
	
	EDIT PATTERN $pat.Name DESELECT ALL	
	CURVEEDITOR MODE DEFAULT CURVEEDITOR SELECT SINGLE_SEGMENT $counter CURVEEDITOR ARC_EDIT MODIFY
	REAL $arc = 0
	$arc = $widget("CEArcEditor.Dimension").value
	IF $arc != 0 AND $arc < $SmallestArc {
		$SmallestArc = $arc
		}
	
	$counter = $counter +1
	}
CURVEEDITOR FINISH ACCEPT

EDIT PATTERN $pat.Name SELECT ALL
EDIT PATTERN $pat.Name MERGE
DIALOGS MESSAGE ON

STRING $msg = "Smallest radius = " + $SmallestArc
MESSAGE INFO $msg
0 Likes
Message 7 of 10

robert.reedHH7Q9
Explorer
Explorer

I was trying to get the longest line in a pattern. I was able to piece something together to accomplish that. You post some very impressive code though, so I would still be interested if you have something for that purpose.

0 Likes
Message 8 of 10

kukelyk
Advisor
Advisor

May the newer Pmills have easier way, but try this one:

 

EDIT PATTERN ; DESELECT ALL
EDIT BLOCK LIMITTYPE PATTERN
EDIT BLOCK RESETLIMIT "10"
EDIT BLOCK RESET
CREATE TOOL ; BALLNOSED
COMMIT PATTERN ;

ENTITY tp = ENTITY('toolpath','')
INT i = 0
REAL LIST segLenLst = {}

DO {
	INT k = add_last($segLenLst, segment_get_length( $tp, $i))
	$i = $i + 1
} WHILE $i < toolpath_component_count($tp, 'segments' )

DELETE TOOLPATH ;
DELETE TOOL ;
REAL lim = MAX($segLenLst)-0.01
EDIT PATTERN ; SELECT LENGTH LT $lim  
EDIT PATTERN ; SELECT INVERT
MESSAGE INFO STRING(MAX($segLenLst))

 

0 Likes
Message 9 of 10

robert.reedHH7Q9
Explorer
Explorer

I'll give that one a shot. This is what I ended up with.

 

CREATE PATTERN ;
RENAME PATTERN # "PROFILE_BOUNDARY"
EDIT PATTERN "PROFILE_BOUNDARY" INSERT BOUNDARY ;
DEACTIVATE Boundary

REAL $ProfileLength = 0.0
INT $Rows = segments(entity('pattern', ''))
if ($Rows > 1) {
EDIT PATTERN "PROFILE_BOUNDARY" CURVEEDITOR START
CURVEEDITOR MODE REORDER
INT $Row = 0
WHILE $Row < $Rows {
STRING $SegLengthStr = list_cell_value('CEReorderSegments.CEListView',$Row,3)
REAL $SegLength = $SegLengthStr
IF ($Seglength > $ProfileLength) {
$ProfileLength = $Seglength
}
$Row = ($Row + 1)
}
CURVEEDITOR MODE DEFAULT
CURVEEDITOR FINISH ACCEPT
$ProfileLength = ($ProfileLength-.01)
EDIT PATTERN "PROFILE_BOUNDARY" SELECT LENGTH LT
$ProfileLength
DELETE PATTERN "PROFILE_BOUNDARY" SELECTED
}

0 Likes
Message 10 of 10

robert.reedHH7Q9
Explorer
Explorer

Actually, I needed that one too. I just figured that would be harder to find. Thank you a whole lot man. It works perfect.

0 Likes