Take the coordinates of each point in the boundary

Take the coordinates of each point in the boundary

HGL-GYY
Enthusiast Enthusiast
999 Views
2 Replies
Message 1 of 3

Take the coordinates of each point in the boundary

HGL-GYY
Enthusiast
Enthusiast

Take the coordinates of each point in the boundary. as the picture shows。QQ截图20170416102631.pngHow to get with the macro

0 Likes
Accepted solutions (2)
1,000 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Accepted solution

The first half of a possible solution (my first Custom Software Core program)

Imports Autodesk.ProductInterface.PowerMILL
Imports Autodesk.Geometry
Imports Autodesk.FileSystem



Module Module1

    Sub Main()
        Dim PMill As New PMAutomation(Autodesk.ProductInterface.InstanceReuse.UseExistingInstance)
        Dim session As PMProject = PMill.ActiveProject
        If session.Boundaries.ActiveItem.Exists Then
            Dim P As List(Of Polyline) = session.Boundaries.ActiveItem.ToPolylines
            Dim f As New File(session.Directory.Path + session.Boundaries.ActiveItem.Name + ".dat")
            Dim sXYZ As String = ""

            For Each i1 In P
                sXYZ &= Str(i1.Count) & " "
            Next
            sXYZ &= vbCrLf
            For Each i1 In P
                For Each i2 In i1
                    sXYZ &= i2.X.ToString & " " & i2.Y.ToString & " " & i2.Z.ToString & vbCrLf
                Next
            Next
            f.Create()
            f.WriteText(sXYZ)
            MsgBox(session.Directory.Path + session.Boundaries.ActiveItem.Name + ".dat" + " created")
        Else
            MsgBox("Active Boundary missing")
        End If

    End Sub

End Module

The program connect to active Powermill, get active boundary, convert to polylines, write it the project folder (file name is the same as active boundary+.dat) 

The first line contains the number of points, the other rows contain the coordinates.

 

Message 3 of 3

Anonymous
Not applicable
Accepted solution

Sample macro for reload points from file:

FUNCTION MAIN {
   IF project_pathname(0) == '' {
      MESSAGE INFO 'Pls. save the project'
      RETURN
   }
   IF NOT entity_exists('boundary','') {
      MESSAGE INFO 'Pls. select boundary'
      RETURN
   }
   STRING ActiveBoundary=entity('boundary','').name
   STRING datFile=project_pathname(0)+'/'+$ActiveBoundary+'.dat'
   IF NOT file_exists($datFile) {
      MESSAGE INFO $datFile+' not found'
      RETURN
   }
   STRING B1=""
   STRING LIST B2={}
   FILE OPEN $datFile FOR READ AS input
   FILE READ $b1 FROM input
   FILE READ $b2 FROM input
   FILE CLOSE input
   STRING LIST B11=tokens($b1)
   INT LIST BoundarySizes={}
   INT PointsNumber=0
   FOREACH I IN $B11 {
      $PointsNumber=$PointsNumber+int($i)
      INT k=add_last($BoundarySizes,$PointsNumber)
   }
   IF $PointsNumber != size($B2) {
      MESSAGE INFO $datFile+' wrong data'
      RETURN
   }
   STRING NewBoundary=$ActiveBoundary+'_reload'
   CALL NewName('boundary',$NewBoundary)
   FOREACH I In $B2 {
      STRING LIST XYZ={}
      $XYZ=tokens($i)
      IF size($XYZ) != 3 {
         MESSAGE INFO $datFile+' wrong data'
         RETURN
      }
   }
   GRAPHICS LOCK
   CREATE BOUNDARY $NewBoundary SKETCH FORM BOUNDARY
   EDIT BOUNDARY $NewBoundary PRIVATE NO
   EDIT BOUNDARY $NewBoundary AUTOREPLAY NO
   EDIT BOUNDARY $NewBoundary CURVEEDITOR NOGUI START
   CURVEEDITOR MODE LINE_MULTI
   STATUS GRID OFF
   INT K=0
   FOREACH J IN $BoundarySizes {
      WHILE $k < $j {
         STRING LIST XYZ={}
         $XYZ=tokens($b2[$k])
         REAL X=real($XYZ[0])
         REAL Y=real($XYZ[1])
         REAL Z=real($XYZ[2])
         MODE COORDINPUT COORDINATES  $X $Y $Z
         $k=$k+1
      }
      CURVEEDITOR LINE_MULTI CLOSE
   }
   CURVEEDITOR MODE DEFAULT
   CURVEEDITOR FINISH ACCEPT
   Yes
   EDIT BOUNDARY $newBoundary ACCEPT BOUNDARY ACCEPT
   GRAPHICS UNLOCK
   MESSAGE INFO 'Success'
}

FUNCTION NewName(STRING EntityType,OUTPUT STRING NewName)
{
   IF NOT entity_exists($EntityType,$NewName) {
      RETURN
   }
   $NewName=new_entity_name($EntityType,$NewName)
}
0 Likes