import a 3d dwg to part

Library for macros
User avatar
doobes
Posts: 132
Joined: Sat Apr 16, 2022 5:59 pm
Answers: 1
Location: Williamsburg, VA
x 12
x 84
Contact:

import a 3d dwg to part

Unread post by doobes »

Hey there,

I'm fairly VBA centric, but this one has me flummoxed.

I've got a butt load of old 3D dwg's that I got from KraftMaid years ago, which are cabinet models.

Way back yonder, I used SketchUp to design a kitchen, but I'm doing a new kitchen and want to use Swx.

I can't for the life of me figure out how to import a dwg into a part instead of a drawing or a sketch via the API.

I've got a nice macro for importing folders of step files and saving to SolidWork parts that I was leveraging for this, but SolidWorks is insistent on importing the dwg's either into drawings or sketches.

I can do this manually. I've tried recording a macro doing it and that's useless as running it again imports the dwg as a drawing.

Any thoughts?

Thanks
chris
User avatar
SPerman
Posts: 2056
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 14
x 2227
x 1878
Contact:

Re: import a 3d dwg to part

Unread post by SPerman »

While in the part, select a plane for the sketch to be placed upon, and select "insert", then "DXF/DWG"
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
User avatar
doobes
Posts: 132
Joined: Sat Apr 16, 2022 5:59 pm
Answers: 1
Location: Williamsburg, VA
x 12
x 84
Contact:

Re: import a 3d dwg to part

Unread post by doobes »

Not what I'm trying to do.

You can open a dxf/dwg from the dialog as a part by selecting that option.

Can't figure out how to do that programmatically.
chris
User avatar
SPerman
Posts: 2056
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 14
x 2227
x 1878
Contact:

Re: import a 3d dwg to part

Unread post by SPerman »

Does this help at all? I know it isn't importing it the way you want, but it's a start. It's probably a matter of figuring out how to set the arguments.

https://help.solidworks.com/2017/englis ... ple_VB.htm

https://help.solidworks.com/2017/englis ... file4.html

https://help.solidworks.com/2017/englis ... gData.html

Looking through those links, it doesn't look like what you want is an option.
image.png
image.png (7.72 KiB) Viewed 2529 times
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
User avatar
AlexB
Posts: 501
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 28
x 269
x 445

Re: import a 3d dwg to part

Unread post by AlexB »

SPerman wrote: Thu Jul 14, 2022 6:38 pm Does this help at all? I know it isn't importing it the way you want, but it's a start. It's probably a matter of figuring out how to set the arguments.

https://help.solidworks.com/2017/englis ... ple_VB.htm

https://help.solidworks.com/2017/englis ... file4.html

https://help.solidworks.com/2017/englis ... gData.html

Looking through those links, it doesn't look like what you want is an option.

image.png
I was going to suggest the same thing, but I tried it out and it puts all the entities into a sketch for any argument that applies to a part file. I'm not sure of a way to get it to convert the dxf into curve features.
User avatar
doobes
Posts: 132
Joined: Sat Apr 16, 2022 5:59 pm
Answers: 1
Location: Williamsburg, VA
x 12
x 84
Contact:

Re: import a 3d dwg to part

Unread post by doobes »

Okay,

I've dug through the API doc's with limited/no success.

Here's what I'm trying to automate:

1) Open a dwg file:
file dialog.JPG
2) Select the "import to new part as: 3D curves or model"
import dialog.JPG
3) Choose the correct settings:
document settings.JPG
4) and Voila!, part:
result.JPG
If I do a macro record of this, which then looks like this:

Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = Application.SldWorks

boolstatus = swApp.LoadFile2("V:\Engineering\Mechanical\Models\KraftMaid\Office\CAD_DKD362D.dwg", "0 0")
Set Part = swApp.ActiveDoc
End Sub

This is the end result:
macro result.JPG
Definitely not what I'm looking for.

I've played around with this code:

Sub main()

Dim swApp As SldWorks.SldWorks
Dim filename As String
Dim longerrors As Long
Dim retVal As Boolean

Dim importData As SldWorks.ImportDxfDwgData

filename = "V:\Engineering\Mechanical\Models\KraftMaid\Base Cabinets\CAD_BPPSFCC3627.dwg"
Set swApp = Application.SldWorks

Set importData = swApp.GetImportFileData(filename)
importData.ImportMethod("") = SwConst.swImportModelItemsFromEntireModel

Dim newDoc As SldWorks.ModelDoc2
Set newDoc = swApp.LoadFile4(filename, "r", importData, longerrors)

End Sub

The problem is there are about eleventy-seven options for the import method and the import data values.

I've tried a bunch of them with no success. Some do nothing at all, some open the file as a drawing.

Any ideas?

Thanks,
chris
User avatar
doobes
Posts: 132
Joined: Sat Apr 16, 2022 5:59 pm
Answers: 1
Location: Williamsburg, VA
x 12
x 84
Contact:

Re: import a 3d dwg to part

Unread post by doobes »

Wow, just wow. Just for fun, I went over to the SolidWorks user forum to see if I could find anything there.

That's friggen useless. No topic segregation so everything just get jammed together. The chances of finding anything are remote, and I suspect any message asking for assistance is going to get lost in the noise.

So, I filed a support request. That's 2 in 2 days! I'm on a roll....
chris
User avatar
AlexLachance
Posts: 2187
Joined: Thu Mar 11, 2021 8:14 am
Answers: 17
Location: Quebec
x 2373
x 2015

Re: import a 3d dwg to part

Unread post by AlexLachance »

@josh might be of help. He's like THE reference in these type of things :P

Do you have an example model we could use to try it on our end..? Maybe your issue is version dependant..?
User avatar
doobes
Posts: 132
Joined: Sat Apr 16, 2022 5:59 pm
Answers: 1
Location: Williamsburg, VA
x 12
x 84
Contact:

Re: import a 3d dwg to part

Unread post by doobes »

Can't attach a dwg, so it's here: https://www.dubea.com/CAD_DKD362D.dwg

Thanks
chris
User avatar
doobes
Posts: 132
Joined: Sat Apr 16, 2022 5:59 pm
Answers: 1
Location: Williamsburg, VA
x 12
x 84
Contact:

Re: import a 3d dwg to part

Unread post by doobes »

Mod's, would you please move this discussion to "API"?

I put this in the wrong place.

Thanks in advance
chris
Post Reply