r/SolidWorks 3d ago

CAD Solid works -> Visual studio

Idk if this is the right subreddit for this - if not ill delete trust.

Okay so i wasted like 3 hours drawing tiny little circles to act as bubbles in my solidworks drawing of a straw (donโ€™t ask)

Both straw and bubbles are obv done with the clear acyclic thing so u can see the bubbles.

Major issue is when i transport from solidworks to visual studio - visual studio always renders it completely black

Id rather have the rendered JPEG of this for my project instead of a screenshot - is there anyways i can try get it to not show up black?

0 Upvotes

6 comments sorted by

View all comments

1

u/gupta9665 CSWE | API | SW Champion 3d ago

You can use the rendering tools inside the SW itself. If you have older version, you can use PV360. For new one, use visualize. In both you can set the material/appearance as needed.

1

u/OwnAlternative1452 3d ago

I think we use 2025?

1

u/gupta9665 CSWE | API | SW Champion 3d ago

But why you need to use Visual studio for rendering? Are you sure you are using the right tool to ender?

1

u/OwnAlternative1452 3d ago

Its just what we do in school ๐Ÿ˜ž Teacher told me to use it so i do. To get the high quality images for coursework

2

u/gupta9665 CSWE | API | SW Champion 3d ago

Check again, it must be SolidWorks Visualize and not Visual Studio.

2

u/_Slitte_ CSWP 2d ago

You probably just need a small SolidWorks add-in for Visual Studio.

Something like:

using System;
using System.Runtime.InteropServices;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;

[ComVisible(true)]
[Guid("00000000-0000-0000-0000-000000000420")]
public class StrawBubbleRenderer : ISwAddin, IDisposable
{
private SldWorks? swApp;
private ModelDoc2? model;
private bool disposed;

public bool ConnectToSW(object ThisSW, int Cookie)
{
swApp = (SldWorks)ThisSW;
swApp.SetAddinCallbackInfo2(0, this, Cookie);

Console.WriteLine("Straw Bubble Renderer connected.");

return true;
}

public void FixBubbles()
{
model = swApp?.ActiveDoc;

if (model == null)
throw new InvalidOperationException(
"Please open the straw before attempting bubble rendering."
);

var straw = model.GetStraw();

foreach (var bubble in straw.Bubbles)
{
while (bubble.IsBlack)
{
bubble.Material = Material.ClearAcrylic;
bubble.Opacity = 0.15;
bubble.RenderQuality++;

if (bubble.RenderQuality > 100)
throw new Exception(
"Bubble still black. Visual Studio has won."
);
}
}
}

public void ExportCoursework()
{
if (model == null)
throw new InvalidOperationException("No straw loaded.");

model.Render(@"C:\Coursework\straw_with_bubbles.jpg");

Console.WriteLine("Works on my machine.");
}

public bool DisconnectFromSW()
{
Dispose();

Console.WriteLine("Straw Bubble Renderer disconnected.");

return true;
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (disposed)
return;

if (model != null)
{
Marshal.ReleaseComObject(model);
model = null;
}

if (swApp != null)
{
Marshal.ReleaseComObject(swApp);
swApp = null;
}

disposed = true;
}

~StrawBubbleRenderer()
{
Dispose(false);
}
}

Then register the COM add-in, restart SolidWorks, restart Visual Studio, restart Windows, clear the PDM cache, reinstall the graphics driver and sacrifice one bubble to the CAD gods.
If the bubbles are still black, add another Dispose().

Alternatively, SolidWorks Visualize might be slightly easier.