SolidWorks二次开发—特定坐标系输出

SolidWorks二次开发—特定坐标系输出

这个功能比较简单,我就直接上代码了。


       private void btnOutWithCoordSystem_Click(object sender, EventArgs e)
        {
            SldWorks swApp = Utility.ConnectToSolidWorks();

            ModelDoc2 swModel = (ModelDoc2)swApp.ActiveDoc;

            //设置用来导出文件的坐标系名称(需要装配体中有这个名称的坐标系)
            var setRes = swModel.Extension.SetUserPreferenceString(16, 0, "Coordinate System1");

            //设置导出版本

            int error = 0;

            int warnings = 0;
            //x_t的版本设置
            //swApp.SetUserPreferenceIntegerValue((int)swUserPreferenceIntegerValue_e.swParasolidOutputVersion, (int)swParasolidOutputVersion_e.swParasolidOutputVersion_161);

            swModel.Extension.SaveAs(@"D:\export.igs", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref error, ref warnings);
            swModel.Extension.SaveAs(@"D:\export.x_t", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref error, ref warnings);
            //Mark:SolidWorks 2018版本导出 step 用坐标系导出有bug!!! x_t igs没有问题
            //swModel.Extension.SaveAs(@"D:\export.step", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref error, ref warnings);

            MessageBox.Show("输出成功");
        }

导出完成后用Solidworks打开。

去掉这个选项,检查一下:

posted @
2021-05-10 09:48 
painezeng  阅读(
0)  评论(
0
编辑 
收藏 
举报  
来源

SolidWorks二次开发-关于录制宏保存的格式

SolidWorks二次开发-关于录制宏保存的格式

对于录制宏操作之后,之前的版本是可以直接另存了Vb.net 或者C# 的格式的文件的,虽然它只是VSTA的项目,但是语法基本是一样的。

刚接触SolidWorks二次开的小伙伴可能只知道swp这个原始格式。

而且Solidworks中还专门有个选项,如2018中

并且很多电脑上宏录制完成之后 ,根本就没有其它格式,只有swp.

这是为什么呢? 我们今天来看看官方的说明,打开API 帮助文件。

搜索一下VSTA这个关键字。

Prerequisite Software 
Installing VSTA 
Creating a .NET macro in SOLIDWORKS 2018 
Editing a .NET macro created in SOLIDWORKS 2018 
Upgrading a .NET macro created in SOLIDWORKS 2017 or earlier 
Running a .NET DLL created in SOLIDWORKS 2017 or earlier 
Prerequisite Software
Microsoft Visual Studio 2015 (Community, Professional, Premium or Enterprise version) must be installed in order to record, edit, or debug VB.NET and C# macros using VSTA (3.0) 2015 in SOLIDWORKS 2018. 
Notes: 

If you install a version of Microsoft Visual Studio that is later than 2015, you must ensure that a runtime version of Microsoft Visual Studio 2015 is also installed. 
If you do not install Microsoft Visual Studio 2015 before you install SOLIDWORKS 2018, you will not be able to record, edit, or debug VSTA 3.0 macros. You will only be able to run VSTA 3.0 DLLs. 
If you install Microsoft Visual Studio 2015 after you install SOLIDWORKS 2018, you must also install the VSTA runtime to record, edit, or debug VSTA 3.0 macros. 
Installing VSTA
SOLIDWORKS 2017 and earlier used VSTA 1.0 to create, edit, and run .NET macros. SOLIDWORKS 2018 supports both VSTA 1.0 and VSTA (3.0) 2015. SOLIDWORKS 2018 activates VSTA (3.0) 2015 by default on all Windows versions. If VSTA 3.0 is enabled, .NET macros created in previous releases are converted when they are edited in this release. If VSTA 3.0 is enabled, be sure to back up your VSTA 1.0 macros before editing them in SOLIDWORKS 2018. If you do not want to convert your .NET macros, you can still edit and run VSTA 1.0 macros in this release, provided you choose to install VSTA 1.0 during the SOLIDWORKS installation and then de-select Tools > Options > System Options > General > Enable VSTA VERSION 3.0.

If you need to edit or run VSTA 1.0 macros on:

Windows 8 or later machines:

During SOLIDWORKS 2018 installation, click Change above the Products window on the Summary screen. 
Expand SOLIDWORKS in the Product Selection window. 
Select Visual Studio Tools for Applications (VSTA). 
On the Summary screen, click Install Now. 
During installation, a message box appears with "An app on your PC needs the following Windows feature: .NET Framework 3.5 (includes .NET 2.0 and 3.0)." Click Download and install this feature. If you do not select to download and install this feature, then VSTA 1.0 will not work. 
Visual Studio Tools (1.0), Visual Studio Tools 2015, and other components are installed. 
Windows 7 machines:

During SOLIDWORKS 2018 installation, click Change above the Products window on the Summary page. 
Expand SOLIDWORKS in the Product Selection window. 
Visual Studio Tools for Applications (VSTA) is selected by default to install VSTA 2015 and VSTA 1.0. After installing .NET Framework 4.6.2, a system reboot occurs. When the system comes back up, Visual Studio Tools 2015 and the remaining components are installed. If VSTA is de-selected in the installer, then VSTA 1.0 is not installed. 
After installing SOLIDWORKS 2018:

Select Tools > Options > System Options > General > Enable VSTA VERSION 3.0 to configure VSTA (3.0) 2015. When opened, .NET macros created in previous releases are converted to VSTA 2015, and an instance of Visual Studio 2015 opens the converted .NET macro for editing. See Prerequisite Software.
  
If you prefer to use VSTA 1.0 to edit or run VSTA 1.0 macros created in previous releases, you must first activate VSTA 1.0 by de-selecting Tools > Options > System Options > General > Enable VSTA VERSION 3.0. 
Note: You  must have installed VSTA during SOLIDWORKS 2018 installation. 
  
Tools > Macro > Edit > Open > File name dropdown contains:
 
SW VBA Macros (*.swp) 
SW VSTA VB Macro (*.vbproj) 
SW VSTA C# Macro (*.csproj) 
SW Macros (*.swp, *.swb, *.csproj, *.vbproj)
  
Tools > Macro > New > Save As > Save as type dropdown contains:
 
SW VBA Macros (*.swp) 
SW VSTA VB Macro (*.vbproj) 
SW VSTA C# Macro (*.csproj)
  
If you did not select to install VSTA when you installed SOLIDWORKS, then all of the SOLIDWORKS macro dialog dropdowns contain only: 
        SW VBA Macros (*.swp)

You cannot modify or repair your SOLIDWORKS installation to add VSTA. You must uninstall and re-install SOLIDWORKS, selecting to install Visual Studio Tools for Applications (VSTA) during the installation. 
Creating a .NET macro in SOLIDWORKS 2018 using VSTA 3.0
Read Installing VSTA. 
In SOLIDWORKS, select Tools > Macro > New. 
In the Save As dialog, navigate to the directory where to save the project. 
Specify File name. 
In Save as type select SW VSTA VB Macro (*.vbproj) or SW VSTA C# Macro (*.csproj). 
Click Save. 
A new instance of Visual Studio 2015 opens. See Prerequisite Software. 
Solution Explorer shows:
The solution, VstaProjects. 
The project name. 
My Project 
References (sldworks and swconst interop assemblies added from install_dir\api\redist\) 
SolidWorksMacro.vb or SolidWorksMacro.cs. 
The SolidWorksMacro class is assigned a GUID attribute. If you change this attribute, the macro will not run. 
When you compile the macro, the project's configuration (Debug or Release) and output directory are not read. Only a release DLL is saved in project_folder/bin. 
Editing a .NET macro created in SOLIDWORKS 2018 using VSTA 3.0
Read Installing VSTA. 
In SOLIDWORKS, select Tools > Macro > Edit. 
In the Open dialog, navigate to the project folder. 
Select SW Macros in the project type dropdown. 
Select the *.vbproj or *.csproj project file. 
Click Open. 
A new instance of Visual Studio 2015 opens the project you selected. See Prerequisite Software. 
Upgrading a .NET macro created in SOLIDWORKS 2017 or earlier
Read Installing VSTA. 
If VSTA 3.0 is enabled, be sure to back up your VSTA 1.0 .NET macro files before editing them in SOLIDWORKS 2018. 
In order to successfully upgrade a .NET macro, the class name, "SolidWorksMacro", and the method name, "Execute", must be preserved. If you renamed those entities in your VSTA 1.0 macro, the macro cannot be upgraded to VSTA 2015. 
In SOLIDWORKS, select Tools > Macro > Edit. 
In the Open dialog, navigate to the SwMacro directory of the project folder created in a previous release. 
Select SW Macros in the project type dropdown. 
Select the *.vbproj or *.csproj project file. 
Click Open. 
A new project is created in project_folder/SwMacro/upgradedmacro. 
A new instance of Visual Studio 2015 opens the upgraded project. See Prerequisite Software. 
When you compile the macro, the project's configuration (Debug or Release) and output directory are not read. Only a release DLL is saved in project_folder/SwMacro/upgradedmacro/bin. 
The original macro is not modified or moved. 
Running a .NET DLL created in SOLIDWORKS 2017 or earlier
Read Installing VSTA. If you selected to install VSTA 1.0, and de-selected Tools > Options > System Options > General > Enable VSTA VERSION 3.0, you can edit or run VSTA 1.0 macros. If you did not install VSTA 1.0, then VSTA 2015 is active by default, and you must upgrade VSTA 1.0 macros to VSTA 2015: 

Follow the instructions in Upgrading a .NET macro created in SOLIDWORKS 2017 or earlier. 
Select Tools > Macro > Run. 
Select SW VSTA Macros (*.dll) in the file type dropdown. 
Navigate to project_folder\SwMacro\upgradedmacro\bin. 
Select the DLL. 
Click Open to run the macro. 

其实官方说了很多,其实很容易看懂的。
和安装(需要单独去选VSTA环境)以及选项都有关系。
因为我不常用这种方式,毕竟一部分操作通过宏也是录制不到的,而且用swp格式也非常方便,录好的代码自己再使用VS环境再写一次,能更好的加深印象,理解和消化掉知识点。

所以我还是建议大家不要纠结这个录制的格式,习惯就好了,花太多时间去弄这个没必要的环境,不划算。
而且直接用VS 比那个方便的多。

posted @
2021-04-08 15:24 
painezeng  阅读(
0)  评论(
0
编辑 
收藏 
举报  
来源

SolidWorks二次开发—高级配合(轮廓中心)

SolidWorks二次开发—高级配合(轮廓中心)

今天有网友咨询高级配合中的面中心配合无法生成。所以我特意来测试了一下,做个总结。
先打开简单的装配体,确认配合操作。

开始录制宏:

点击Mate ,切换到高级配合中的轮廓中心配合。

再选第一步确定的2个面,配合自动完成了。

停止录制,然后保存录制的文件,然后用最后面的编辑按钮打开刚保存过的swp文件。

录制出来的宏,其实都有英文的注释。把Solidworks退回一步,取消掉我们刚刚手动配合的操作。
直接在VBA宏编辑器中按F5,Solidworks就再次把这个面中心的配合做好了。
下面是我大概注释的几步,大家可以参考修改为自己想要的代码,如vb.net 或者C#

当然我们还可以去API中搜索一下 这个配合所出来的关键字:

录制出来的关键字:
ProfileCenterMateFeatureData

API中也只是给了一个VBA的例子,大家可以参考的去看看,实现一下。

后来网友说他也是用C#。但是就是不成功,我就来改成C#的来测试,也是可以了,就是设置配合对象的时候要动态转换。

源码如下:

            //请先分别在两个零件中选中用于轮廓配合的面。
            //连接到Solidworks
            SldWorks swApp = Utility.ConnectToSolidWorks();

            ModelDoc2 swModel = (ModelDoc2)swApp.ActiveDoc;

            Face2 swSelFace = default(Face2);
            Face2 swSelFace2 = default(Face2);

            SelectionMgr swSelMgr = (SelectionMgr)swModel.SelectionManager;

            //获取选择数据
            SelectData swSelData = default(SelectData);

            swSelData = swSelMgr.CreateSelectData();

            swSelFace = (Face2)swSelMgr.GetSelectedObject6(1, 0);
            swSelFace2 = (Face2)swSelMgr.GetSelectedObject6(2, 0);

            var swAsmembly = swModel as AssemblyDoc;

            ProfileCenterMateFeatureData profileCenterMateFeatureData =
                (ProfileCenterMateFeatureData)swAsmembly.CreateMateData((int)swMateType_e.swMatePROFILECENTER);

            object[] mateFaces = new object[2];

            mateFaces[0] = swSelFace;
            mateFaces[1] = swSelFace2;

            var lisFaces = (DispatchWrapper[])ObjectArrayToDispatchWrapperArray((mateFaces));

            profileCenterMateFeatureData.EntitiesToMate = lisFaces;

            profileCenterMateFeatureData.MateAlignment = 0;

            profileCenterMateFeatureData.LockRotation = false;

            profileCenterMateFeatureData.FlipDimension = false;

            profileCenterMateFeatureData.OffsetDistance = 0;

            Feature newMateFeature = (Feature)swAsmembly.CreateMate(profileCenterMateFeatureData);

            swModel.EditRebuild3();

            if (newMateFeature != null)
            {
                MessageBox.Show("配合完成。");
            }

选中两个圆的面,执行之后:

完成,我顺带查了下api,EntitiesToMate中根本没有C#相关的写法,所以不好理解这里面的东西。


源代码还是老地方,有兴趣的自己拿。

posted @
2021-04-02 15:42 
painezeng  阅读(
0)  评论(
0
编辑 
收藏 
举报  
来源

C# SolidWorks 二次开发 API —获取预览图

C# SolidWorks 二次开发 API —获取预览图

最近有网友问到如何在界面上简单的显示一个预览图,就类似于资源管理器中显示的图片。
今天来带大家找一找,首先在我共享的中文翻译中搜索一下:“预览

我们找到了几个有用的。
先看这一个: 第一列是Web 帮助的地址,当然也可以去本地api帮助中查看。


vba中还有个例 子
问题是这帮助写的只能是进程内使用,像exe还不行。
继续看下面的,有另一个方法:

这个方法看描述好像可以使用:
Gets the specified preview bitmap of a document and saves it as a Windows bitmap file (.bmp) using the specified filename.

写上代码:

ISldWorks swApp = Utility.ConnectToSolidWorks();

            //此处路径请自己确保存在。
            string fileName = @"D:\09_Study\CSharpAndSolidWorks\CSharpAndSolidWorks\TemplateModel\bodies.sldasm";

            string configName = "Default";

            string bitmapPathName = @"D:\09_Study\CSharpAndSolidWorks\CSharpAndSolidWorks\TemplateModel\bodies.bmp";

            var status = swApp.GetPreviewBitmapFile(fileName, configName, bitmapPathName);

            if (System.IO.File.Exists(bitmapPathName))
            {
                swApp.SendMsgToUser("预览图获取完成。");
            }

结果出来的颜色有点怪,不理想。

到这里想了下,我们可以直接获取系统资源管理器的预览图,而不需要利用solidworks来处理。
这个就直接百度,找一找资源就行了。
我找了个类,直接调用 ,就可以获取到文件了,后缀是.li ,很奇怪的格式。

找到文件,复制到当前零件的文件夹。改后缀为.bmp,ok了。

这是利用系统的api的获取的,如果只是单配置零件也比较完美了。这种好像不能获取不同配置的预览图。

在查询api帮助的时候发现,在Document Manager API 中也提供了获取预览图的功能。
注意,这里需要一个key, 正版用户请找对应的代理商获取,每一个版本的key都不一样,并且带公司名称。


里面还有实例,那我们就来试试吧:
测试时发现,document mgr从2018开始,只支持64位程序。所以测试时大家要把编译的选项改成x64位的,不然一直会报无法创建dll的实例。

 			const string sLicenseKey = "your_license_key"; //这个不好公开。请下载代码 

            string sDocFileName = fileName;

            SwDMClassFactory swClassFact = default(SwDMClassFactory);
            SwDMApplication swDocMgr = default(SwDMApplication);
            SwDMDocument swDoc = default(SwDMDocument);
            SwDMDocument10 swDoc10 = default(SwDMDocument10);
            SwDmDocumentType nDocType = 0;
            SwDmDocumentOpenError nRetVal = 0;
            SwDmPreviewError nError = 0;

            // Determine type of SOLIDWORKS file based on file extension
            if (sDocFileName.EndsWith("sldprt"))
            {
                nDocType = SwDmDocumentType.swDmDocumentPart;
            }
            else if (sDocFileName.EndsWith("sldasm"))
            {
                nDocType = SwDmDocumentType.swDmDocumentAssembly;
            }
            else if (sDocFileName.EndsWith("slddrw"))
            {
                nDocType = SwDmDocumentType.swDmDocumentDrawing;
            }
            else
            {
                // Probably not a SOLIDWORKS file,
                // so cannot open
                nDocType = SwDmDocumentType.swDmDocumentUnknown;
                return;
            }

            swClassFact = new SwDMClassFactory();
            swDocMgr = (SwDMApplication)swClassFact.GetApplication(sLicenseKey);
            swDoc = (SwDMDocument)swDocMgr.GetDocument(sDocFileName, nDocType, true, out nRetVal);
            Debug.Print("File = " + swDoc.FullName);
            Debug.Print(" Version = " + swDoc.GetVersion());
            Debug.Print(" Author = " + swDoc.Author);
            Debug.Print(" Comments = " + swDoc.Comments);
            Debug.Print(" CreationDate = " + swDoc.CreationDate);
            Debug.Print(" Keywords = " + swDoc.Keywords);
            Debug.Print(" LastSavedBy = " + swDoc.LastSavedBy);
            Debug.Print(" LastSavedDate = " + swDoc.LastSavedDate);
            Debug.Print(" Subject = " + swDoc.Subject);
            Debug.Print(" Title = " + swDoc.Title);

            swDoc10 = (SwDMDocument10)swDoc;
            // SwDMDocument10::GetPreviewBitmap throws an unmanaged COM exception
            // for out-of-process C# console applications
            // Use the following code in SOLIDWORKS C# macros and add-ins
            object objBitMap = swDoc10.GetPreviewBitmap(out nError);
            System.Drawing.Image imgPreview = PictureDispConverter.Convert(objBitMap);
            imgPreview.Save(bitmapPathName, System.Drawing.Imaging.ImageFormat.Bmp);
            imgPreview.Dispose();

            Debug.Print(" Preview stream = " + swDoc10.PreviewStreamName);

执行成功之后 ,我们颜色不对的预览图就被替换成功了。

当然 ,现在也还是只是获取了最后保存的那个配置的缩略图。
如何获取别的配置的呢?
这个方法的备注里面有说明: 需要用别的方法:

里面有个实例:
Get PNG Preview Bitmap and Stream for Configuration Example (C#)
核心就在这里,需要去遍历配置。当然 ,如果知道配置名称,就不需要遍历一次了。
下面的代码我没有测试哈

 swCfgMgr = swDoc.ConfigurationManager;
 
                Debug.Print("File = " + swDoc.FullName);
                Debug.Print("Active configuration name = " + swCfgMgr.GetActiveConfigurationName());
                vCfgNameArr = (string[])swCfgMgr.GetConfigurationNames();
 
                foreach (string vCfgName in vCfgNameArr)
                {
 
                    swCfg = (SwDMConfiguration7)swCfgMgr.GetConfigurationByName(vCfgName);
                    // SwDMConfiguration7::GetPreviewPNGBitmap throws an unmanaged COM exception 
                    // for out-of-process C# console applications
                    // Use the following code in SOLIDWORKS C# macros and add-ins 
                    object objBitMap = swCfg.GetPreviewPNGBitmap(out nError);
                    System.Drawing.Image imgPreview = PictureDispConverter.Convert(objBitMap);
                    imgPreview.Save("C:\\temp\\" + vCfgName + ".PNG", System.Drawing.Imaging.ImageFormat.Png);
                    imgPreview.Dispose();
 
                    Debug.Print(" " + vCfgName);
                    Debug.Print(" PNG preview stream = " + swCfg.PreviewPNGStreamName);
 
                    Debug.Print(" ");
                }

posted @
2020-05-09 14:09 
painezeng  阅读(
292)  评论(
0
编辑 
收藏 
举报

C# SolidWorks 二次开发 API —注释引用点的坑

C# SolidWorks 二次开发 API —注释引用点的坑

最近有个小需求,就是要把注释箭头指向的点的坐标提取出来。
刚开始发现Note.GetAttachPos功能,Annotation.GetPosition有这个功能。
但是经过测试发现,当注释的引线是多折线的时候,上两个函数就是读取的位置有时候对,有时候不对。
本来可以想着把所有的第二种换成第一种,那么获取的时候就应该正确了,但是发现API里面还不能直接转换。

经过大量的调试发现,如果使用的是多折线,但是只有一条折线信息的时候,可能是对的,如果是多折的,基本上不对。
当鼠标移动到引线上时,默认的一段直线直接显示的是注释的图标,当移动到是多段折线上时,显示的是另一个图标,说明它们不是一个对象。而更像是一个组合体。

经过api的检查,发现了这个多折线有一个专门的对象。里面是由多个线的信息组成。

然后又发现Annotation中两个方法 GetMultiJogLeaderCount 和 GetMultiJogLeaders,所以就更显明了。
在获取注释对象 Note的引用点位置时,需要做一个判断。
当GetMultiJogLeaderCount > 0 时,那么说明它是一个多折线的注释,需要使用 MultiJogLeader 来获取信息。遍历其它的关键点坐标。
这个坐标和视图的位置与比例有一定关联,它默认是的整个图纸的坐标。如果需要转换到视图中,还需要做个计算。

下面是一段宏的代码:

Option Explicit
Sub main()
    Dim swApp           As SldWorks.SldWorks
    Dim swModel         As ModelDoc2
    Dim swDraw          As DrawingDoc
    Dim swSelMgr        As SelectionMgr
    Dim swNote          As Note
    Dim swView          As View
    Dim viewPos         As Variant
    Dim notePos         As Variant
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    
     Dim ann As Annotation
     
    If Not swModel Is Nothing Then
        If swModel.GetType <> swDocumentTypes_e.swDocDRAWING Then Exit Sub
        Set swDraw = swModel
        Set swSelMgr = swModel.SelectionManager
        
        Dim selLeaders As SldWorks.MultiJogLeader
          Dim lineData As Variant
          
          
          If swSelMgr.GetSelectedObjectType3(1, -1) <> swSelectType_e.swSelNOTES Then Exit Sub
          
        Set swNote = swSelMgr.GetSelectedObject6(1, 0)
        
        Set swView = swDraw.ActiveDrawingView
        viewPos = swView.Position
        notePos = swNote.GetAttachPos
       
        Set ann = swNote.GetAnnotation
                  
         If ann.GetMultiJogLeaderCount > 0 Then
         
         
         Set selLeaders = ann.GetMultiJogLeaders(0)
         
           If selLeaders Is Nothing = False Then
           
            
            lineData = selLeaders.GetLineAtIndex(0)
            For i = 0 To selLeaders.GetLineCount - 1
            
                 lineData = selLeaders.GetLineAtIndex(i)
                If Not IsEmpty(lineData) Then
                    
                    Debug.Print ("x:" & Math.Round((lineData(1) - viewPos(0)) * 1000# / swView.ScaleDecimal, 4))
                    Debug.Print ("y:" & Math.Round((lineData(2) - viewPos(1)) * 1000# / swView.ScaleDecimal, 4))
                                
                    
                End If
            Next i
           End If
           
           Else
           
         
         End If

           
       
        
' 'ann.UseDocDispLeader = True
       'Debug.Print (swView.Angle * 57.295779513)
' Debug.Print (Math.Round((notePos(0) - viewPos(0)) * 1000# / swView.ScaleDecimal, 4))
' Debug.Print (Math.Round((notePos(1) - viewPos(1)) * 1000# / swView.ScaleDecimal, 4))
' Debug.Print
    End If
End Sub

反之,按正常的GetAttachPos获取对象就可以了。

posted @
2020-05-02 16:55 
painezeng  阅读(
138)  评论(
0
编辑 
收藏 
举报

C# SolidWorks 二次开发 API —在自己的网页中嵌入eDrawings Web Viewer

C# SolidWorks 二次开发 API —在自己的网页中嵌入eDrawings Web Viewer

这是Solidworks PDM系统中的Web2客户端,能够实现对很多3D图在web端的预览,我们先不考虑PDM这么 高深的问题,今天我来给大家介绍一下如何把这个功能集成到自己的网页中,实现预览3D格式。

通过网页端的请求分析,以及后端服务器的对比,发现web版的edrawing是利用了新的scs格式来进行中转的,没有直接在web上对solidworks的原档进行解析,这样保证了数据的安全。

它利用了一个在线的服务来进行文件的转换,下图是3dcontentcentral这个网站上的请求截图:


在发布好web2客户端后,发现里面会有一个eDrawingsWebViewer的文件夹:里面就有转换的文件夹,再次进行研究

找到了一个转换的Exe文件,在cmd命令下直接有提示,传入输入的格式,以及输出的地址,就可以转换成scs文件了。
经过测试,这个转换工具可以直接转换x_t step等中间格式为scs文件,还是很厉害的。

最后在本地部署iis下直接 在Site文件夹下 打开main.html,并传入URL即可显示:


当前它本来有一个中转的服务,这个需要大家自己去处理。目前还没在把服务研究透。

下面是测量的截图

posted @
2020-04-30 21:37 
painezeng  阅读(
389)  评论(
2
编辑 
收藏 
举报