Community
HSM Support Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

.net API HSMWorks

36 REPLIES 36
Reply
Message 1 of 37
Michael.winter.1980
1045 Views, 36 Replies

.net API HSMWorks

Dear Sir or Madam,

 

I'm using the code as follows:

 

<DllImport("C:\Program Files\HSMXpress\hsmsw.dll", CallingConvention:=CallingConvention.Cdecl)> _
    Private Shared Function HSMWorks_regenerateAll(ByRef document As IModelDoc2, ByVal Waitfortask As Boolean) As Integer
    End Function
    

   

Private Sub hsmtest()
        'Dim s As UIntPtr = oSwAppCls.ActiveDoc
        Dim nMajor As UInteger
        Dim nMinor As UInteger
        Dim nMicro As UInteger
        Dim nBuild As UInteger
        Dim nResult As Integer
        nResult = HSMWorks_getVersion(nMajor, nMinor, nMicro, nBuild)
        MsgBox(nMajor.ToString + vbCrLf + nMinor.ToString + vbCrLf + nMicro.ToString + vbCrLf+ nBuild.ToString)

        Dim oSwModelDoc2 As IModelDoc2 = oSwAppCls.IActiveDoc2
 oSwModelDoc2.Rebuild(1)
        nResult = HSMWorks_regenerateAll(oSwModelDoc2, False)


    End Sub

Debugger results:

 

In line MsgBox I get the message 9 1 0 38078. Seem the interface is working.

Line oSwModelDoc2.Rebuild(1) brings no error. (oSwModelDoc2 is not empty)

Line HSMWorks_regenerateAll(oSwModelDoc2, False) ends with AccessViolationException.

 

Up till now im not familiar with passing the pointer of a SolidWorks document to an unmanaged dll.

 

Could you please give some advices?

 

Thank You very much.

 

Michael Winter

36 REPLIES 36
Message 2 of 37
Anonymous
in reply to: Michael.winter.1980

not sure about VB.net but using C# i had to explicity marshal the document object into an IUnknown pointer. As such-->

 

IntPtr docPointer = Marshal::GetIUnknownForObject(modelDoc);
IUnknown* document = (IUnknown*)docPointer.ToPointer();

Message 3 of 37
johannes.wanner9SKDQ
in reply to: Anonymous

I'm sorry I pushed that old issue up.

But I have exactly the same question!

Does anyone have a solution (some code) for vb.net?

Thank a lot!

Message 4 of 37
johannes.wanner9SKDQ
in reply to: Anonymous

Doesn't anyone have an idea?

The HSMWorks_dummy() and the HSMWorks_getVersion() function does work.

<DllImport("C:\Program Files\HSMXpress\hsmsw.dll", CallingConvention:=CallingConvention.Cdecl)> _
    Private Shared Function HSMWorks_regenerateAll(ByRef document As IModelDoc2, ByVal Waitfortask As Boolean) As Integer
    End Function
    
 Private Sub hsmtest()
        'Dim s As UIntPtr = oSwAppCls.ActiveDoc
        Dim nMajor As UInteger
        Dim nMinor As UInteger
        Dim nMicro As UInteger
        Dim nBuild As UInteger
        Dim nResult As Integer
        nResult = HSMWorks_getVersion(nMajor, nMinor, nMicro, nBuild)
        MsgBox(nMajor.ToString + vbCrLf + nMinor.ToString + vbCrLf + nMicro.ToString + vbCrLf+ nBuild.ToString)

        Dim oSwModelDoc2 As IModelDoc2 = oSwAppCls.IActiveDoc2
 oSwModelDoc2.Rebuild(1)
        nResult = HSMWorks_regenerateAll(oSwModelDoc2, False)


    End Sub

 

Now I have problems to convert this C# pointer code into vb.net.

IntPtr docPointer = Marshal::GetIUnknownForObject(modelDoc);
IUnknown* document = (IUnknown*)docPointer.ToPointer();

Does anyone has a solution or a work around?

Message 5 of 37

Please can you answer this topic? I created API in C# and C++. I hae got same problem everywhere

 

Message 6 of 37
jeff.pek
in reply to: nejkov

Can you share what you've written?

  Jeff

Message 7 of 37

The text file attached to this has the bulk of the code converted to work in vb.net

There is a function in there called GetObjPtr,  use that in any instance where the function is calling for an IntPtr

 

Here is an example in use for getting the program comment

 

Dim strBuffer(4096) As Char
Dim size As UInteger = 4096
HSMWorks_getJobParameter(SWDoc, JobID, "programComment", GetObjPtr(strBuffer), size)
Dim retval As String = strBuffer
retval = retval.Replace(vbNullChar, "")
Return retval

 

SWDoc is the Modeldoc2 object in solidwokrs.

 

I hope this helps

 

Message 8 of 37

Thanks. How are you using this VB.NET? Is this running in the Solidworks process?

  Jeff

Message 9 of 37

I am running it as part of a dll add-in for solidworks.   I just finished writing thos this morning.  One correction on those, there are a few I hadn't tested yet, and it seems I needed to add 'As UInteger' as the return type to several of them (forgot the return type).

Once I've tested all of them I will re load the library.  This is part of larger project to automate a lot of the redundant  tasks in solidworks. 

Message 10 of 37

Thank you very much. Maybe I'll try it.
But now I continue thanks to the example sent to me by venkatesh.thiyagarajan. 
I believe I have already solved the problem

Message 11 of 37


Display of tracks

 

I created an API that creates toolpaths.

I can see "External toolpath" operation in the list of Operations. But I can´t see any paths.
To see the paths, I must go into simulation. Problem is, that all paths are yellow (Rapids). NC code after postprocessing looks OK.
Is this normal?

 

What should i do to make the tracks blue and I can see it not only in simulation.
Can I add my moves to an existing operation so that everything behaves by default?

 

Thank you 

Adam

Message 12 of 37
jeff.pek
in reply to: nejkov

Hi -

Do you have a model and/or code you can share? Do you have the View Toolpath command available for the external toolpath? How is it that you're creating that?

 

Thanks,

  Jeff

Message 13 of 37

I call non-exported function from hsmsw.dll. You can see the code in HSMWorks.h
Where can I find "View Toolpath command for the external toolpath" ?

Message 14 of 37

 I have got it. View ToolPath command is there, but there are not any paths.

Message 15 of 37

I can export paths and it looks OK

Message 16 of 37

Interesting! I suppose this is something that you worked out with Rene, to get you access to the non-exported entry points to support this. I didn't really know that it was there. Are you able to get me a model that contains one of these external toolpaths? I'll have to dig into why view toolpath doesn't handle it.

 

Thanks,

  Jeff

Message 17 of 37

I see the model is in one of the zips. Will take a look. Thanks.

Message 18 of 37

Try to export paths from my External toolpath operation and compare it with normal operation. I see small differences

 

Normal operation:
<rapid to='57.15 -31.4706 15.24'/>
<rapid to='57.15 -31.4706 3.8354'/>
<linear to='57.15 -31.4706 -1.27' feed='3048'/>
<linear to='-57.15 -31.4706 -1.27' start='yes' end='yes'/>
<arc-ccw to='-57.15 -12.3825 -1.27' center='-57.15 -21.9265 -1.27' normal='0 0 -1'/>

 

External path:
<line number='0'/>
<rapid to='0 0 100'/>
<line number='0'/>
<linear feed='100'/>
<line number='0'/>
<linear to='0 0 10'/>
<line number='0'/>
<linear to='-100 -100 10' feed='200'/>

 

There are no informations: "start='yes' end='yes'" What does it mean? 
I have got Line number there. I do not understand why.

 

Please let me know if it is possible to display the tracks as if it were a standard operation. It's pretty important to me.

Message 19 of 37

Hi again - We've been digging into this. The mechanism that's exposed for the creation of these "external toolpaths" doesn't currently expose the ability to set the movement type (e.g. cutting), and so this information isn't available downstream.

 

Generally, this doesn't matter, as the post processor has enough information based on the feed value.

 

Can you explain how would you want to make use of this information, if it were possible to specify it?

 

Thanks,

  Jeff

Message 20 of 37

My main concern is display and control paths in the HSMWorks environment.

The created paths should be visible outside the simulation too. As is the case with normal operations. Checking them with the "View Toolpath command" would also be good.
I want to create my own operations (fixed tool paths) without binding to geometry and I would like to work with them normally (to simulate, to generate NC code).
Now I can only see paths in simulation but simulalation does not remove material and verification is not applicable.

I assumed that I would be able to create my own, completely new operation using the API. Now I feel that it is completely useless.

Do you have any idea how to insert paths via API using "HSMWorks_onRapid5D", "HSMWorks_onRapid", "SMWorks_onLinear", .... and work with them in the same way as we would create them as a standard operation?

 

Can we use the API to edit the "View Toolpath" table? How?

 

Thanks

 Adam

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report