Site Logo
Site Logo
 
It is currently Sat Mar 25, 2017 1:01 am

All times are UTC [ DST ]




Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 31 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Hole Location Macro
PostPosted: Thu May 01, 2014 8:39 pm 
Offline
DELCAM User
DELCAM User

Joined: Fri Dec 23, 2011 1:16 am
Posts: 49
Location: Windsor, Ontario
Hello All,

I am looking for some help here. I am trying to finish a macro I have created. The macro I have currently will capture curves which are on level set 150 and create a feature set from them. This feature set is for machine setup only. No machining or drilling will take place. I am looking for a way to capture these locations and show the user their locations and possibly print them. Also if there is a way to convert the locations from imperial to metric (round to the nearest whole number). This is what I have so far.

//---CREATES USER DEFINED BOUNDARIES FROM LEVEL 150---//

EXPLORER SELECT Level "Level\150" NEW
EDIT LEVEL "150" SELECT ALL
CREATE BOUNDARY ; SKETCH FORM BOUNDARY
EDIT BOUNDARY ; INSERT MODEL
EDIT BOUNDARY ; ACCEPT BOUNDARY ACCEPT
RENAME BOUNDARY ; "LOCATORS"

//---CREATES FEATURE SETS FROM ABOVE BOUNDARIES---//

EXPLORER SELECT Boundary "Boundary\LOCATORS" NEW
DEACTIVATE BOUNDARY
ACTIVATE BOUNDARY "LOCATORS"
CREATE PATTERN ;
EDIT PATTERN ; INSERT BOUNDARY ;
EXPLORER SELECT Pattern "Pattern\1" NEW
RENAME Pattern ; "LOCATORS"
EXPLORER SELECT Pattern "Pattern\LOCATORS" NEW
EXPLORER SELECT Workplane "Workplane\HOME" NEW
EXPLORER SELECT Pattern "Pattern\LOCATORS" NEW
EDIT PATTERN "LOCATORS" SELECT ALL
CREATE FEATURESET ; FORM FEATURE FEATURECREATE
EDIT FEATURECREATE TYPE HOLE EDIT FEATURECREATE CIRCULAR ON
EDIT FEATURECREATE FILTER CIRCLES EDIT FEATURECREATE TOPDEFINE ABSOLUTE EDIT FEATURECREATE BOTTOMDEFINE ABSOLUTE
EDIT FEATURESET ; INSERT POINTS
FEATURE CLOSE
EXPLORER SELECT Featureset "Featureset\1" NEW
RENAME Featureset ; "LOCATORS"
EXPLORER SELECT Workplane "Workplane\HOME" NEW
EXPLORER SELECT Featureset "Featureset\LOCATORS" NEW
IMPORT TEMPLATE ENTITY TOOLPATH TMPLTSELECTORGUI
CANCEL


Any help would be greatly appreciated :D


Top
 Profile  
 
 Post subject: Re: Hole Location Macro
PostPosted: Fri May 02, 2014 9:21 am 
Offline
DELCAM Staff
DELCAM Staff
User avatar

Joined: Mon Aug 09, 2004 3:55 pm
Posts: 1463
Location: Birmingham UK
You'll need to loop through the items in the featureset using the inbuilt components() function:

Code:
FOREACH feat in components(entity('featureset','name-of-featureset')) {
  // check that you really have a hole
  IF feat.Type == 'hole' {
    // get the world coordinates of the hole centre point
    REAL ARRAY pos =  feat.Point
    // get the position in WP Coordinates
    REAL ARRAY wp_pos = feat.WPPoint
  }
}


Having got the values you can save them to a file. You should check the macro manual for writing and reading files (page 100 of the manual or there about).


Top
 Profile  
 
 Post subject: Re: Hole Location Macro
PostPosted: Fri May 02, 2014 12:02 pm 
Offline
DELCAM User
DELCAM User

Joined: Fri Dec 23, 2011 1:16 am
Posts: 49
Location: Windsor, Ontario
Lloyd wrote:
You'll need to loop through the items in the featureset using the inbuilt components() function:

Code:
FOREACH feat in components(entity('featureset','name-of-featureset')) {
  // check that you really have a hole
  IF feat.Type == 'hole' {
    // get the world coordinates of the hole centre point
    REAL ARRAY pos =  feat.Point
    // get the position in WP Coordinates
    REAL ARRAY wp_pos = feat.WPPoint
  }
}


Having got the values you can save them to a file. You should check the macro manual for writing and reading files (page 100 of the manual or there about).


Thank you Lloyd. I will look into that too!


Top
 Profile  
 
 Post subject: Re: Hole Location Macro
PostPosted: Fri May 02, 2014 4:37 pm 
Offline
DELCAM User
DELCAM User

Joined: Fri Dec 23, 2011 1:16 am
Posts: 49
Location: Windsor, Ontario
Lloyd,

Not sure how close I am but this is what I have so far. The logfile will open to the user but with no information. I'd like to play with this all day but unfortunately I have work to do. If you can spot what I am missing I'd greatly appreciate it.

//---CREATES USER DEFINED BOUNDARIES FROM LEVEL 150---//

EXPLORER SELECT Level "Level\150" NEW
EDIT LEVEL "150" SELECT ALL
CREATE BOUNDARY ; SKETCH FORM BOUNDARY
EDIT BOUNDARY ; INSERT MODEL
EDIT BOUNDARY ; ACCEPT BOUNDARY ACCEPT
RENAME BOUNDARY ; "LOCATORS"

//---CREATES FEATURE SETS FROM ABOVE BOUNDARIES---//

EXPLORER SELECT Boundary "Boundary\LOCATORS" NEW
DEACTIVATE BOUNDARY
ACTIVATE BOUNDARY "LOCATORS"
CREATE PATTERN ;
EDIT PATTERN ; INSERT BOUNDARY ;
EXPLORER SELECT Pattern "Pattern\1" NEW
RENAME Pattern ; "LOCATORS"
EXPLORER SELECT Pattern "Pattern\LOCATORS" NEW
EXPLORER SELECT Workplane "Workplane\HOME" NEW
EXPLORER SELECT Pattern "Pattern\LOCATORS" NEW
EDIT PATTERN "LOCATORS" SELECT ALL
CREATE FEATURESET ; FORM FEATURE FEATURECREATE
EDIT FEATURECREATE TYPE HOLE EDIT FEATURECREATE CIRCULAR ON
EDIT FEATURECREATE FILTER CIRCLES EDIT FEATURECREATE TOPDEFINE ABSOLUTE EDIT FEATURECREATE BOTTOMDEFINE ABSOLUTE
EDIT FEATURESET ; INSERT POINTS
FEATURE CLOSE
EXPLORER SELECT Featureset "Featureset\1" NEW
RENAME Featureset ; "LOCATORS"
EXPLORER SELECT Workplane "Workplane\HOME" NEW
EXPLORER SELECT Featureset "Featureset\LOCATORS" NEW
IMPORT TEMPLATE ENTITY TOOLPATH TMPLTSELECTORGUI
CANCEL

// Specify the folder in which to create the text files. The user must have write permission for this folder!
STRING $Temp_Dir = "C:\temp"

// Define the folder and filename used to save the collision data
// The user must have WRITE permissions for this particular folder!
STRING $filename = $Temp_Dir + "\locators_result.txt"

// Define the filename used to save the LOG file.
STRING $logfile = ""
IF PROJECT_PATHNAME(1) == "" {
$logfile = $Temp_Dir + "\locators_result_file.txt"
} ELSE {
$logfile = $Temp_Dir + "\" + PROJECT_PATHNAME(1) + "_locators_result_file.txt"
}

DIALOGS MESSAGE OFF
FILE CLOSE logfile
FILE CLOSE infile
DIALOGS MESSAGE ON

// Open (Overwrite) the file specified by the user
FILE OPEN $logfile FOR WRITE AS logfile

// Deletes the old results
DELETE FILE C:\temp\locators_result.txt

// Open the logfile in the default editor
OLE FILEACTION 'open' $logfile

FOREACH feat in components(entity('featureset','locators')) {
// check that you really have a hole
IF feat.Type == 'hole' {
// get the world coordinates of the hole centre point
REAL ARRAY pos = feat.Point
// get the position in WP Coordinates
REAL ARRAY wp_pos = feat.WPPoint
}
}


Top
 Profile  
 
 Post subject: Re: Hole Location Macro
PostPosted: Fri May 02, 2014 4:48 pm 
Offline
DELCAM Staff
DELCAM Staff
User avatar

Joined: Mon Aug 09, 2004 3:55 pm
Posts: 1463
Location: Birmingham UK
I think you need to write the data to the logfile before you do the FILEACTION thing. So that should go after the FOREACH loop, and within the FOREACH loop you should be writing the point data to your logfile, probably separated with commas so that you end up with CSV type file.


Top
 Profile  
 
 Post subject: Re: Hole Location Macro
PostPosted: Mon Jun 16, 2014 8:21 pm 
Offline
DELCAM User
DELCAM User

Joined: Fri Dec 23, 2011 1:16 am
Posts: 49
Location: Windsor, Ontario
Lloyd wrote:
I think you need to write the data to the logfile before you do the FILEACTION thing. So that should go after the FOREACH loop, and within the FOREACH loop you should be writing the point data to your logfile, probably separated with commas so that you end up with CSV type file.


I've played with this off and on now for a month now and I still cannot get this to work. There just isn't a whole lot out there to refer to on this type of application. I am hoping you Lloyd or somebody else out there has something else for me to try.


Top
 Profile  
 
 Post subject: Re: Hole Location Macro
PostPosted: Tue Jun 17, 2014 9:36 am 
Offline
DELCAM Staff
DELCAM Staff
User avatar

Joined: Mon Aug 09, 2004 3:55 pm
Posts: 1463
Location: Birmingham UK
Some code that should put data into the file

Code:
FOREACH feat in components(entity('featureset','locators')) {
  // check that you really have a hole
  IF feat.Type == 'hole' {
    // get the world coordinates of the hole centre point
    REAL ARRAY pos = feat.Point
    // get the position in WP Coordinates
    REAL ARRAY wp_pos = feat.WPPoint
    FILE WRITE $pos TO logfile
    FILE WRITE $wp_pos TO logfile
  }
}

// close the file
FILE CLOSE logfile
// Open the logfile in the default editor
OLE FILEACTION 'open' $logfile


NOTE: The the opening of the file is done right at the end after we have closed it. If you do this before you've finished writing to the file you may find that windows has locked it and you can't write to it.

If you need to do some CSV type file then

Code:
STRING data = string(pos[0]) + ',' + pos[1] + ',' + pos[2]
FILE WRITE $data TO logfile
$data = string(wp_pos[0]) + ',' + wp_pos[1] + ',' + wp_pos[2]
FILE WRITE $data TO logfile



Top
 Profile  
 
 Post subject: Re: Hole Location Macro
PostPosted: Tue Jun 17, 2014 6:09 pm 
Offline
DELCAM User
DELCAM User

Joined: Fri Dec 23, 2011 1:16 am
Posts: 49
Location: Windsor, Ontario
// Open (Overwrite) the file specified by the user
FILE OPEN $logfile FOR WRITE AS logfile

// Deletes the old results
DELETE FILE C:\temp\locators_result_file.txt


FOREACH feat in components(entity('featureset','LOCATORS')) {
IF feat.Type == 'hole' {
REAL ARRAY pos = feat.Point
REAL ARRAY wp_pos = feat.WPPoint

STRING data = string(pos[0]) + ',' + pos[1] + ',' + pos[2] + ',' + pos[3]
FILE WRITE $data TO logfile
$data = string(wp_pos[0]) + ',' + wp_pos[1] + ',' + wp_pos[2] + ',' + wp_pos[3]
FILE WRITE $data TO logfile
}
}

FILE CLOSE logfile


OLE FILEACTION 'open' $logfile

I ended up changing the "LOCATORS" to uppercase in the FOREACH line. I wasn't sure if that command is case sensitive. But once I changed it, the macro craps out on the "REAL ARRAY pos = feat.point" line. Could there be something wrong here? possibly a faulty command? Since I had "locators" in lower case before, I am wondering if the macro was just ignoring this line.


Top
 Profile  
 
 Post subject: Re: Hole Location Macro
PostPosted: Tue Jun 17, 2014 11:52 pm 
Offline
New User
New User

Joined: Tue Jun 17, 2014 11:45 pm
Posts: 2
Are you not just missing the [3] as in:

REAL ARRAY pos[3] = feat.point


Top
 Profile  
 
 Post subject: Re: Hole Location Macro
PostPosted: Wed Jun 18, 2014 9:14 am 
Offline
DELCAM Staff
DELCAM Staff
User avatar

Joined: Mon Aug 09, 2004 3:55 pm
Posts: 1463
Location: Birmingham UK
charles jones wrote:


Hi kid how are you? Feeling better?


Top
 Profile  
 
 Post subject: Re: Hole Location Macro
PostPosted: Wed Jun 18, 2014 10:41 am 
Offline
Site Admin

Joined: Wed Feb 16, 2005 4:57 pm
Posts: 668
Location: Birmingham, UK
Hope you're doing OK, Charlie.


Top
 Profile  
 
 Post subject: Re: Hole Location Macro
PostPosted: Wed Jun 18, 2014 3:39 pm 
Offline
New User
New User

Joined: Tue Jun 17, 2014 11:45 pm
Posts: 2
Hi Guys,

Doing well cheers! Hopefully be able to fly home around 1 week tomorrow; although the weather here has been rainy and miserable so I’m feeling right at home! :D


Top
 Profile  
 
 Post subject: Re: Hole Location Macro
PostPosted: Thu Jun 19, 2014 4:57 pm 
Offline
DELCAM Staff
DELCAM Staff

Joined: Fri Oct 01, 2004 11:35 am
Posts: 495
Location: Birmingham UK
Other members of the forum are probably not aware that "Charles Jones" is not well after catching a particularly contagious disease after an evening in a Salt Lake City nightclub.


Top
 Profile  
 
 Post subject: Re: Hole Location Macro
PostPosted: Fri Jun 20, 2014 2:29 pm 
Offline
DELCAM Guru
DELCAM Guru
User avatar

Joined: Fri Dec 09, 2005 2:28 pm
Posts: 209
Location: Detroit Michigan Area
Have you recorded the steps ? it is easy to make a macro this way. ???

_________________
Thanks
ERN


Top
 Profile  
 
 Post subject: Re: Hole Location Macro
PostPosted: Fri Jun 20, 2014 6:31 pm 
Offline
DELCAM User
DELCAM User

Joined: Fri Dec 23, 2011 1:16 am
Posts: 49
Location: Windsor, Ontario
learn wrote:
Have you recorded the steps ? it is easy to make a macro this way. ???


Not sure I know what you mean...please explain :?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 31 posts ]  Go to page 1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB