AnsweredAssumed Answered

How do I specify the face of a part to create a sketch?

Question asked by Evgenij Polupan on Apr 2, 2020

Good afternoon. Please tell me how to specify the face of the part to create a sketch?

 

using SolidWorks.Interop.sldworks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Kromka
{
static class Program
{
[STAThread]
static void Main()
{
SldWorks swApp;
ModelDoc2 swModel;
SelectionMgr swSelMgr;
Edge swEdge = null;
object[] vFace = null;
Face2 swFace = default(Face2);
UserProgressBar pb = null;
Entity swEnt = null;
Component2 swComp;
bool boolstatus;
int nRetval = 0;
AssemblyDoc swAssy = default(AssemblyDoc);
int nInfo = 0;
string PPPPPP;

 

swApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application"); // Плучаем экземпляр запущенного SolidWorks
swModel = (ModelDoc2)swApp.ActiveDoc; // Сохранение в переменную ссылки на открытый документ
swSelMgr = swModel.SelectionManager;
swApp.GetUserProgressBar(out pb); // Получает индикатор состояния пользователя.
pb.Start(0, 100, "Укажите кромку грани которую нужно закромковать (Shift-отмена)");
pb.UpdateProgress(0);
while (swEdge == null)
{
if (Control.ModifierKeys != 0)
{
MessageBox.Show("Выход", "ОШИБКА!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); // Вывод окна сообщения
return;
}
try
{
swEdge = swSelMgr.GetSelectedObject6(1, -1);
swEnt = swSelMgr.GetSelectedObject6(1, -1);
}
catch
{
swEdge = null;
MessageBox.Show("Выбрана не кромка.", "ОШИБКА!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); // Вывод окна сообщения
swModel.ClearSelection2(true);
pb.UpdateProgress(0);
}
}
vFace = swEdge.GetTwoAdjacentFaces2();
Body2 PPP = swEdge.GetBody();
swFace = (Face2)vFace[0];
int Pob = swFace.GetFaceId();
double Ploch = swFace.GetArea();
swFace = (Face2)vFace[1];
double Ploch1 = swFace.GetArea();
if (Ploch > Ploch1)
{
swFace = (Face2)vFace[0];
}
else
{
swFace = (Face2)vFace[1];
}
swComp = swEnt.GetComponent();
string PPPPP = swComp.Name2;
if(PPPPP.IndexOf("^") != -1)
{
PPPPPP = PPPPP.Remove(0, PPPPP.IndexOf("^")+1);
PPPPP = PPPPP + "@" + PPPPPP;
}
boolstatus = swModel.Extension.SelectByID2(PPPPP, "COMPONENT", 0, 0, 0, false, 0, null, 0);
swAssy = (AssemblyDoc)swModel;
nRetval = swAssy.EditPart2(true, true, ref nInfo);

 

// Next, you need to specify "seFace" a face and create a sketch on it


}
}
}

Outcomes