Converting STEP files to DWG pogramatically (C#)

Converting STEP files to DWG pogramatically (C#)

Anonymous
Not applicable
3,220 Views
10 Replies
Message 1 of 11

Converting STEP files to DWG pogramatically (C#)

Anonymous
Not applicable

Hello,

 

I'm trying to import a STEP (.stp) into AutoCAD 2016 and save it as DWG, which works as a user.

The main problem is about emulating the "import" command.

I didn't find any way to import in managed code, so I tried interop:

 

 

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Windows;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.Interop;
using AcadInterop = Autodesk.AutoCAD.Interop.AcadApplication;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Geometry;

 

[CommandMethod("steptodwg", (CommandFlags.Modal | CommandFlags.Session))]
public void Convert()

{

try
{

Document doc = AcadApp.DocumentManager.MdiActiveDocument;

AcadDocument comDoc = (Autodesk.AutoCAD.Interop.AcadDocument)doc.GetAcadDocument();

double myScale = 1;

double[] ptArray = { 1, 1, 0 };

comDoc.Import(@"C:\test.stp", (object)ptArray, myScale);

}

.....

 

The message is "Invalid argument".

 

I suppose the argument causing problems is the point of insertion, but I can't say for sure.

 

Thanks

0 Likes
Accepted solutions (1)
3,221 Views
10 Replies
Replies (10)
Message 2 of 11

ampster40
Advisor
Advisor
sorry I cannot assist with the code, just providing the simple fact that AutoCAD by itself cannot work with step files. If you want to work with step files in Acad, you will also need to have AutoCAD Mechanical installed. Perhaps the code you're working on will need to be modified to work in conjunction with Acad Mech. HTH
0 Likes
Message 3 of 11

ampster40
Advisor
Advisor
also, instead of working with the "import" command, try utilizing the "stepin" command.
0 Likes
Message 4 of 11

Anonymous
Not applicable

Thanks for your answers, i didn't know about mechanical, but i don't have it and it works (as a user).

I don't have access to the "stepin" command"n what does it do? Is it only in mechanical?

0 Likes
Message 5 of 11

JDMather
Consultant
Consultant

@ampster40 wrote:
.... the simple fact that AutoCAD by itself cannot work with step files. If you want to work with step files in Acad, you will also need to have AutoCAD Mechanical installed.

Incorrect information. 
Vanilla AutoCAD has been able to import STEP files for at least a couple of releases now.

 

AutoCAD Imports File Types.png


-----------------------------------------------------------------------------------------
Autodesk Inventor 2019 Certified Professional
Autodesk AutoCAD 2013 Certified Professional
Certified SolidWorks Professional


Message 6 of 11

Patchy
Mentor
Mentor

Can it be done? Read this from Autodesk

 

http://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2016/ENU/AutoCA...

 

Look at where it said STEP.

0 Likes
Message 7 of 11

Anonymous
Not applicable

@ampster40 wrote:
sorry I cannot assist with the code, just providing the simple fact that AutoCAD by itself cannot work with step files. If you want to work with step files inAcad, you will also need to have AutoCAD Mechanical installed. Perhaps the code you're working on will need to be modified to work in conjunction withAcadMech.HTH

This is so wrong.....You can import step files with vanilla AutoCAD.

0 Likes
Message 8 of 11

ampster40
Advisor
Advisor
Tks JD, you are correct. It only handles 1/2 of the step file situation. It cannot export but it can import. Sorry for the bad info.
0 Likes
Message 9 of 11

Anonymous
Not applicable

As I said in the 1st post, I could do it as a user, so that's not the problem at all.

No offense, but I'm looking for developper's advices here.

Thanks for your answers anyway.

0 Likes
Message 10 of 11

Patchy
Mentor
Mentor

Then you need to go to proper group, not autocad users group.

Dig in here:

http://forums.autodesk.com/t5/custom/page/page-id/Discussions-Page

0 Likes
Message 11 of 11

Anonymous
Not applicable
Accepted solution

@Anonymous wrote:

As I said in the 1st post, I could do it as a user, so that's not the problem at all.

No offense, but I'm looking for developper's advices here.

Thanks for your answers anyway.


Maybe look in the proper forum....

 

http://forums.autodesk.com/t5/autocad-customization/ct-p/AutoCADTopic1

0 Likes