AnsweredAssumed Answered

adding parts into an Assembly C#

Question asked by Макс Сергеев on Mar 18, 2017
Latest reply on Mar 21, 2017 by Amen Allah Jlili

Good day! Please tell me how to add multiple parts in an Assembly in C#. The macro does not help. Created the Assembly, but the part is not added.

 

using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

using System.Runtime.InteropServices;

using System;

 

namespace Macro1.csproj

{

    public partial class SolidWorksMacro

    {

        public void Main()

        {

            ModelDoc2 swDoc = null;

            PartDoc swPart = null;

            DrawingDoc swDrawing = null;

            AssemblyDoc swAssembly = null;

            bool boolstatus = false;

            int longstatus = 0;

            int longwarnings = 0;

            swDoc = ((ModelDoc2)(swApp.NewDocument("C:\\ProgramData\\SolidWorks\\SolidWorks 2016\\templates\\gost-assy.asmdot", 0, 0, 0)));

            swApp.ActivateDoc2("Сборка2", false, ref longstatus);

            swDoc = ((ModelDoc2)(swApp.ActiveDoc));

            ModelView myModelView = null;

            myModelView = ((ModelView)(swDoc.ActiveView));

            myModelView.FrameState = ((int)(swWindowState_e.swWindowMaximized));

            swAssembly = ((AssemblyDoc)(swDoc));

            boolstatus = swAssembly.AddComponent("C:\\Users\\Desktop\\fgfg.SLDPRT", 0.027620825299025514, 0.072698020262157451, 0.15179969937013105);

        }

 

        /// <summary>

        ///  The SldWorks swApp variable is pre-assigned for you.

        /// </summary>

        public SldWorks swApp;

    }

}

Outcomes