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:

User Controls with x64


Recommended Posts

I'm having a couple issues developing NEThooks for 2018 and defining User Controls. When I build the project for x64 it can't load the user controls in the Visual Studio designer, see error message attached (but they do seem to work properly when I load the Nethook in Mastercam.) If I build the project for Any CPU it can load the user controls properly, but gives a warning that there's a processer mismatch.

I could load the custom controls as a reference as suggested here, but wanted to check if there was any better solution to the problem. Could I switch to WPF rather than Forms, get an Any CPU version of the NETHook dll, etc. Any ideas?

2018-04-13 13_31_51-CustomToolNethook - Microsoft Visual Studio.png

Link to comment
Share on other sites

If you want to use Designer in Visual Studio you need to build with AnyCPU.

The Designer is not "smart" enough to handle a 64-bit built assembly. (Visual Studio is a 32-bit Application!)

The "Processor Mismatch" is just that - a warning.

You can build AnyCPU during development and then switch over to 64-bit for your production build.

Link to comment
Share on other sites

Thanks, Roger. The main reason I asked is that I've been having some strange issues loading the NETHook3_0 dll and I was wondering if it was related. Seems like it's a separate issue, though, I separated out all the user controls this morning and I'm still having the problem.

When I open the designer for my main form with specific user controls on it the below error is thrown. If I ignore and continue, the form is very unstable, I've lost all contents and code a couple times for now clear reason. But the project builds and seems to run OK.

The issue seems to be the ToolGeometry class (see the definition below.) If I have any reference to that on the user control it there's an error, otherwise it's fine. I've had the same thing happen before with references to Mastercam.IO.LevelsManager: any references to it errors the designer but it seems to build and work just fine. Any ideas what I'm doing wrong?

5ad4f422c13f4_2018-04-1614_54_58-Clipboard.thumb.png.e0cd85e9c79b88ecd8705ea6c3275ed1.png

Imports Mastercam.Math

''' <summary>
''' This class contains all geometry for drawing a new tool
''' </summary>
Public Class ToolGeometry

    Dim pts() As Point3D,
        rounds() As Double,
        flats() As Double,
        errors() As String,
        axisPoint As New Point3D(0, 0, 0)

    ''' <summary>
    ''' The set of points that should be drawn, stored as an array of Mastercam Point3d
    ''' </summary>
    ''' <returns></returns>
    Public Property Points As Point3D()
        Get
            Return pts
        End Get
        Set(value As Point3D())
            pts = value
        End Set
    End Property

    ''' <summary>
    ''' An array of fillet sizes for each corner in the array
    ''' </summary>
    ''' <returns></returns>
    Public Property Fillets As Double()
        Get
            Return rounds
        End Get
        Set(value As Double())
            rounds = value
        End Set
    End Property

    ''' <summary>
    ''' An array of chamfer sizes for each corner in the array
    ''' </summary>
    ''' <returns></returns>
    Public Property Chamfers As Double()
        Get
            Return flats
        End Get
        Set(value As Double())
            flats = value
        End Set
    End Property

    ''' <summary>
    ''' The origin that MasterCAM axes will pass through
    ''' </summary>
    ''' <returns></returns>
    Public Property Origin As Point3D
        Get
            Return axisPoint
        End Get
        Set(value As Point3D)
            axisPoint = value
        End Set
    End Property

    ''' <summary>
    ''' This sub appends a given point to the end of the points list
    ''' </summary>
    ''' <param name="point">The point to append as a Point3D</param>
    Public Sub AddPoint(point As Point3D)
        pts = AppendPoint(pts, point)
    End Sub

    ''' <summary>
    ''' This sub appends a given XYZ value as a new point to the end of the points list
    ''' </summary>
    ''' <param name="XValue">X position of the new point</param>
    ''' <param name="YValue">Y position of the new point</param>
    ''' <param name="ZValue">Z position of the new point</param>
    Public Sub AddPoint(XValue As Double, YValue As Double, Optional ZValue As Double = 0)
        pts = AppendPoint(pts, New Point3D(XValue, YValue, ZValue))
    End Sub

    ''' <summary>
    ''' This sub adds a new value to the chamfer list
    ''' </summary>
    ''' <param name="Size">Size of the chamfer, 0 for null</param>
    Public Sub AddChamfer(Size As Double)
        flats = AppendDouble(flats, Size)
    End Sub

    ''' <summary>
    ''' This sub adds a new value to the fillet list
    ''' </summary>
    ''' <param name="Size">Size of the fillet, 0 for null</param>
    Public Sub AddFillet(Size As Double)
        rounds = AppendDouble(rounds, Size)
    End Sub

    ''' <summary>
    ''' Scales all points, fillets, and chamfers by a scaling factor
    ''' </summary>
    ''' <param name="factor">Factor to scale all points by</param>
    Public Sub Scale(factor As Double)

        If factor = 1 Then Exit Sub ' Skip math if null scale

        For i = LBound(pts) To UBound(pts)
            pts(i).x = pts(i).x * factor
            pts(i).y = pts(i).y * factor
            pts(i).z = pts(i).z * factor
        Next

        For i = LBound(flats) To UBound(flats)
            flats(i) = flats(i) * factor
        Next

        For i = LBound(rounds) To UBound(rounds)
            rounds(i) = rounds(i) * factor
        Next

        axisPoint = New Point3D(axisPoint.x * factor, axisPoint.y * factor, axisPoint.z * factor)

    End Sub

    ''' <summary>
    ''' Translates all points by a vector
    ''' </summary>
    ''' <param name="translation">A vector, represented by a Point3D, to translate the whole sketch by</param>
    Public Sub Translate(translation As Point3D)
        For i = LBound(pts) To UBound(pts)
            pts(i) = New Point3D(pts(i).x + translation.x, pts(i).y + translation.y, pts(i).z + translation.z)
        Next

        ' Translate the axis origin
        axisPoint = New Point3D(axisPoint.x + translation.x, axisPoint.y + translation.y, axisPoint.z + translation.z)
    End Sub

    ''' <summary>
    ''' This sub gets rid of any identical points in the array
    ''' </summary>
    Public Sub CleanGeometry()
        Dim returnPts() As Point3D = Nothing,
            returnFlats() As Double = Nothing,
            returnRounds() As Double = Nothing

        ' Add the first points
        returnPts = AppendPoint(returnPts, pts(LBound(pts)))
        returnFlats = AppendDouble(returnFlats, LBound(flats))
        returnRounds = AppendDouble(returnRounds, LBound(rounds))

        ' Iterates through all the points, appending all non-duplicates to the new arrays
        For i = LBound(pts) + 1 To UBound(pts)
            If Not PointsEqual(pts(i), pts(i - 1)) Then
                returnPts = AppendPoint(returnPts, pts(i))
                returnFlats = AppendDouble(returnFlats, flats(i))
                returnRounds = AppendDouble(returnRounds, rounds(i))
            End If
        Next

        ' Sets new arrays
        pts = returnPts
        flats = returnFlats
        rounds = returnRounds

    End Sub

    ''' <summary>
    ''' Flips the tool geometry around an axis
    ''' </summary>
    ''' <param name="axis"></param>
    Public Sub FlipGeometry(axis As String)
        Dim xFactor As Double = 1, yFactor As Double = 1, zFactor As Double = 1

        ' Selects which axis to flip around
        Select Case UCase(axis)
            Case "X"
                xFactor = -1
            Case "Y"
                yFactor = -1
            Case "Z"
                zFactor = -1
        End Select

        ' Flips all points
        For i = LBound(pts) To UBound(pts)
            pts(i) = New Point3D(pts(i).x * xFactor, pts(i).y * yFactor, pts(i).z * zFactor)
        Next

        ' Flip the axis point
        axisPoint = New Point3D(axisPoint.x * xFactor, axisPoint.y * yFactor, axisPoint.z * zFactor)

    End Sub

End Class

 

Link to comment
Share on other sites

When I attempt to load the main form into the Winformes Designer I get 2 errors.
1> Could not load file or assembly NETHook3_0 ....
2> The variable "ToolPreview1" is either undeclared or was never assigned.
#1 - Doesn't make much sense, as I know that the NETHook3_0 reference in both projects is set correctly.
#2 - Hmmm... I commented out all references to "ToolPreview1" in MainView.vb and MainView.Designer.vb files.
And now the MainView.vb [Design] will load into the WinForms Designer.
Even though this obviously doesn't fix everything, it at least leads us to where a problem appears to be.
 

Link to comment
Share on other sites

Yup, that's exactly what I'm getting. It will also work if you comment out all code in the ToolPreview control in the Classes project. Clearly there's an issue with the code on that form, I'm just not sure what it is. It seems like it might be the ToolGeometry class, since it throws the error even if only the Dim tool as ToolGeometry is the only thing there.

Most of what I need to do does not involve designer changes to the main form, so I do have a workaround. If I need to use the designer I remove all the code from the ToolPreview control and rebuild, then add the code back in after I've finished my edits. It's awkward but it does seem to work.

Link to comment
Share on other sites

I did some more looking at the situation with the ToolPreview (user-control) class.
What makes it different, that the WinForms Designer cannot handle it properly?
I noticed that it’s the only user-control class that directly references the NETHook3 API.
The NETHook3_0.DLL is a 64-bit Assembly, and we know that WinForms Designer does not handle 64-bit well.
If you remove any use (references) to the NETHook API in the user-controls, the MainForm of the project will now load in the WinForms Designer.

Link to comment
Share on other sites

Sorry for the delayed response, I've been out of the office.

I could have sworn I'd tried that, but I guess I missed something somehow. Ultimately I think my best option is to completely split the project: fully isolate the user controls and classes from the NETHook dll in the AnyCPU project, handle all interface with MasterCAM in the x64 project. Seems to be working fine.

Thanks for all the help, Roger!

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