Community
PowerShape and PowerMill API Forum
Welcome to Autodesk’s PowerShape and PowerMill API Forums. Share your knowledge, ask questions, and explore popular API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to use Visual Studio2022 connecter powershape and Entrez un fichier dgk pour le convertir en fichier IGS

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
lizhipeng1987324
784 Views, 11 Replies

How to use Visual Studio2022 connecter powershape and Entrez un fichier dgk pour le convertir en fichier IGS

I need your help,thank you

How to use Visual Studio2022 connecter powershape and Entrez un fichier "dgk" pour le convertir en fichier "XT"

Can you provide an example?

The following code can only obtain "A.XT.DGK", But I need to get "A.XT",  How to implement it?


Imports Autodesk.ProductInterface.PowerSHAPE
Imports Autodesk.Geometry
Imports System.Windows.Forms

 

Public Class Form1

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim powerSHAPE As New PSAutomation(Autodesk.ProductInterface.InstanceReuse.UseExistingInstance)
powerSHAPE.Reset()
'Dim psModel As PSModel = powerSHAPE.ActiveModel()
Dim psModel As PSModel = powerSHAPE.Models.CreateEmptyModel()
powerSHAPE.FormUpdateOff()
powerSHAPE.RefreshOff()
powerSHAPE.DialogsOff()
Dim importFile As Autodesk.FileSystem.File = New Autodesk.FileSystem.File("D:\DGK\A.dgk")
Dim exportFile As New Autodesk.FileSystem.File("D:\XT\A.XT")
psModel.Import(importFile)
psModel.Export(exportFile, ExportItemsOptions.Visible)
powerSHAPE.FormUpdateOn()
powerSHAPE.RefreshOn()
powerSHAPE.DialogsOn()
End Sub

End Class

11 REPLIES 11
Message 2 of 12

Hallo,

 

I use :

Dim xtfile As New Autodesk.FileSystem.File(Fname & ".xt")
PSModel.Export(xtfile, ExportItemsOptions.All, ExportWorkplanes.World)

 

Fname being the name of the file, ex "A"

Message 3 of 12

thank you but The test result is "A.xt.dgk"
The result is not correct,,,i want get "A.xt"
Message 4 of 12

.x_t,,,
I Found the problem
Message 5 of 12

yes. Sorry, the extension is x_t, not xt.

Message 6 of 12

Hi,
if you realy only want to automate the file translation, I would recommend using Autodesk Manufacturing Data Exchange Utility and automate that, as it is used by PowerShape to do the translation in the background anyway.

When you open Exchange, go to Help then The COM interface.
There you can find instructions how to automate Autodesk Manufacturing Data Exchange Utility.


Alexander Keil

Implementation Consultant
EMEA MFG Design & Make Team
Message 7 of 12

Hi Alexander, yes, it is possible, I have a small bit of software doing that :

Private Sub Translate_exchange(ByVal FileName As String)

Dim psx As Object = CreateObject("sdx.AutodeskManufacturingDXU.1")

' hardwired directory for export files
Dim DataExportDir As String = "M:\Exchange Server Export Data\"

' check if ixport file directory exists on the server
If Not System.IO.Directory.Exists(DataExportDir) Then
System.IO.Directory.CreateDirectory(DataExportDir)
End If

' create name export file
Dim ExportFileName As String = System.IO.Path.GetFileNameWithoutExtension(FileName)
ExportFileName = DataExportDir + ExportFileName + ".dgk"

' activate the exhange object and configuration
psx.Attach()

psx.Option("INPUT_FILE") = FileName
psx.Option("OUTPUT_FILE") = ExportFileName
psx.Option("OUTPUT_FORMAT") = "dgk"
psx.Option("LOG_FILE") = "c:\temp\out.log"

' translation starts. Try/catch/finally needed here ?

If psx.CheckOk() = 0 Then

' MessageBox.Show("OK" + vbCrLf + psx.CheckOk.ToString() + vbCrLf)
psx.Execute()
Else
MessageBox.Show("TRANSLATION NOT OK" + vbCrLf + psx.CheckOk.ToString() + vbCrLf)
End If

' desactivate Exchange
psx.Detach()

' release the exchange object. necesaary because the translated file has to be deleted from the import directory.
releaseObject(psx)

'delete translated file
If System.IO.File.Exists(FileName) = True Then
Try
System.IO.File.Delete(FileName)
Catch ex As Exception
FileName = FileName + ".4dcam"
System.IO.File.Delete(FileName)
End Try

End If

End Sub

Private Sub releaseObject(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Catch ex As Exception
obj = Nothing
Finally
GC.Collect()
End Try
End Sub

Message 8 of 12

thank you!
"releaseObject(psx)" This sentence cannot be accepted, otherwise it will terminate the conversion.
Message 9 of 12

Yes, it was meant to terminate the session. It was a server/client application. The software runs on a server constantly watching the contents of a directory. If a cad file arrives in that directory, the file is translated (to dgk in my case). After translation PS Exchange was stopped.

Message 10 of 12

Hi Luc,

yes, thank you.
I use it in some applications myself.

Just a small addon to your code.
You should wait for the translation to finish before Detach by either subscribing to the onFinished event or checking get_Finished.
E.g.

 

While psx.Finished != 1
    Thread.Sleep(100)
End While

 


Greetings,
Alex


Alexander Keil

Implementation Consultant
EMEA MFG Design & Make Team
Message 11 of 12

Hallo Alexander,

Thanks. I wrote this code about 7 years ago, and I remember trying a few things (trial and error method as usual) before the thing worked. 

I don't remember if I tried the methods you mentioned. Were they existing 7 years ago?

Luc

Message 12 of 12

VERYGOOD!

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report