Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

Passing parameters to functions (post blocks) - Is it actually possible?


Recommended Posts

When I was browsing through some resources, I came across an example post in one of the CHook projects. I was surprised to see that it seemed to be passing parameters to post blocks when I haven't seen any documentation on this.

Does anyone know how exactly this is intended to work with respect to declaring variables, naming, etc? Any chance a value can also be returned from a postblock?

 

Here's the contents of the file "MPDraw_Ex.mcpost":

[POST_VERSION] #DO NOT MOVE OR ALTER THIS LINE# V20.00 P4 E1 W20.00 T1517249798 M20.00 I0 O0

#region User Settings
#<UserSettings>

MPDrawDebugOutput : no$  # Output arguments passed to the MPDraw.dll
geometryLevel : 101      # Level to create/remove geometry

#</UserSettings>
#endregion End User Settings

#region Post Settings

rotary_type$ : 5

#endregion End Post Settings

#region Format Statments

fs2 1   0.8 0.7
fs2 2   1 0 1 0

#endregion End Format Statments

#region Draw Geometry

#region Geometry Variable Initializations

#region Enumerators

# Geometry type
DELETE@    : 0
LINE@      : 1
ARC@       : 2

# View number
TOP@       : 1
FRONT@     : 2
BACK@      : 3
BOTTOM@    : 4
RIGHT@     : 5
LEFT@      : 6
ISOMETRIC@ : 7

#endregion End Enumerators

#region Numeric Variable Initializations

# Return value for dll function
dllReturn : 0

# Line start and end point variables
lineStartX : 0
lineStartY : 0
lineStartZ : 0
lineEndX   : 0
lineEndY   : 0
lineEndZ   : 0

# Arc variables
arcView        : 0
arcCenterX     : 0
arcCenterY     : 0
arcCenterZ     : 0
arcRadius      : 0
arcStartAngle  : 0
arcEndAngle    : 0

# Line start and end point variables formatted for output to MPDraw.dll
fmt "" 1 sx
fmt "" 1 sy
fmt "" 1 sz
fmt "" 1 ex
fmt "" 1 ey
fmt "" 1 ez

# Arc variables formatted for output to MPDraw.dll
fmt "" 2 arcview
fmt "" 1 acx
fmt "" 1 acy
fmt "" 1 acz
fmt "" 1 ar
fmt "" 1 as
fmt "" 1 ae

# level and geometry type variables formatted for output to MPDraw.dll
fmt "" 2 level
fmt "" 2 geometryType

#endregion End Numeric Variable Initializations

#region String Variable Initializations

ssq    : "'" # Single quote character
sdq    : '"' # Double quote character
sspace : " " # Space character

sMPDrawDLL    = "MPDraw.dll"  # Constant string containg 'MPDraw.dll'
sdeleteData   = "0"           # Constant string to hold the delete data
slineData     : ""            # String to hold the line data
sarcData      : ""            # String to hold the arc data

sMPDeleteArgs     : "" # String to pass the delete arguments to MPDraw.dll
sMPLineArgs       : "" # String to pass the line arguments to MPDraw.dll
sMPArcArgs        : "" # String to pass the arc arguments to MPDraw.dll

#endregion End String Variable Initializations

#endregion End Geometry Variable Initializations

#region Geometry Post Blocks

# Remove all geometry from a specified level
pDeleteGeometry(level)
      # Set the geometryType
      geometryType = DELETE@

      # Construct the delete argument string(sdeleteData, level, geometryType)
      sMPDeleteArgs = ssq + sdq + sdeleteData + sdq + sspace + sdq + drs_str(2, level) + sdq + sspace + sdq + drs_str(2, geometryType) + sdq + ssq

      # Call the MPDraw.dll passing it the constructed argument string
      dllReturn = dll(sMPDrawDLL, sMPDeleteArgs)

      # If MPDrawDebugOutput = yes$, write the delete arguments to the NC file
      if MPDrawDebugOutput, " Delete Arguments : ", *sMPDeleteArgs, e$

# Draw a line on a specified level
pDrawLine(sx, sy, sz, ex, ey, ez, level)
      # Set the geometryType
      geometryType = LINE@

      # Convert the line data to a string
      slineData = drs_str(2, sx) + sspace + drs_str(2, sy) + sspace + drs_str(2, sz) + sspace + drs_str(2, ex) + sspace + drs_str(2, ey) + sspace + drs_str(2, ez)

      # Construct the line argument string(slineData, level, geometryType)
      sMPLineArgs = ssq + sdq + slineData + sdq + sspace + sdq + drs_str(2, level) + sdq + sspace + sdq + drs_str(2, geometryType) + sdq + ssq

      # Call the MPDraw.dll passing it the constructed argument string
      dllReturn = dll(sMPDrawDLL, sMPLineArgs)

      # If MPDrawDebugOutput = yes$, write the line arguments to the NC file
      if MPDrawDebugOutput, " Line Arguments   : ", *sMPLineArgs, e$

# Draw an arc on a specified level
pDrawArc(arcview, acx, acy, acz, ar, as, ae, level)
      # Set the geometryType
      geometryType = ARC@

      # Convert the arc data to a string
      sarcData = drs_str(2, arcview) + sspace + drs_str(2, acx) + sspace + drs_str(2, acy) + sspace + drs_str(2, acz) + sspace + drs_str(2, ar) + sspace + drs_str(2, as) + sspace + drs_str(2, ae)

      # Construct the arc argument string(sarcData, level, geometryType)
      sMPArcArgs = ssq + sdq + sarcData + sdq + sspace + sdq + drs_str(2, level) + sdq + sspace + sdq + drs_str(2, geometryType) + sdq + ssq

      # Call the MPDraw.dll passing it the constructed argument string
      dllReturn = dll(sMPDrawDLL, sMPArcArgs)

      # If MPDrawDebugOutput = yes$, write the arc arguments to the NC file
      if MPDrawDebugOutput, " Arc Arguments    : ", *sMPArcArgs, e$

#endregion End Geometry Post Blocks

#endregion End Draw Geometry

#region System Post Blocks

pheader$  #  pheader$ - in this example this post block runs first
      #  Remove all geometry on a specified level
      pDeleteGeometry(geometryLevel)

psof$  #  psof$ - in this example this post block runs second
      lineStartX = vequ(x$)
      lineEndX = vequ(m7$)
      #  Create a line on a specified level starting from the current x$,y$,z$ and extenting to the tool the toolplane Z
      pDrawLine(lineStartX, lineStartY, lineStartZ, lineEndX, lineEndY, lineEndZ, geometryLevel)

peof$  #  peof$ - in this example this post block runs last
      arcView = TOP@
      arcCenterX = 0
      arcCenterY = 0
      arcCenterZ = 1
      arcRadius = .5
      arcStartAngle = 0
      arcEndAngle = 360
      #  Create an arc on a specified level using the values above
      pDrawArc(arcView, arcCenterX, arcCenterY, arcCenterZ, arcRadius, arcStartAngle, arcEndAngle, geometryLevel)

#endregion End System Post Blocks

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...