Hi all.
My code is running in Structural Modeler V8i(SELECTserice 1).
I want to create a slab form.
but after creating slab form (fn_MakeSlabForm - function name),
an error occurred while trying to execute the StartDefaultCommand().
How can I fix this problem?
below is my class.
Thanks.
class PlaceFormSlabClass : IPrimitiveCommandEvents { [DllImport("stdmdlbltin.dll")] public static extern void mdlState_clear();
private int m_nIndex; private Boolean m_bStop; private Point3d[] m_ptSlab = null; public void Cleanup() { }
public void DataPoint(ref Point3d Point, BCOM.View View) { int nCnt; Point3d[] ptTemp = null; BCOM.Application app = Utilities.ComApp;
if (!m_bStop) { fn_AddPointToPoint3D(ref m_ptSlab, Point, m_nIndex + 1); m_nIndex++;
nCnt = m_ptSlab.Length;
Array.Resize<Point3d>(ref ptTemp, nCnt + 1); m_ptSlab.CopyTo(ptTemp, 0);
if (m_nIndex == 1) { app.ShowCommand("Place Slab Form"); app.ShowPrompt("Enter shape vertex"); app.CommandState.StartDynamics(); } else if (m_nIndex > 2) { app.ShowCommand("Place Slab Form"); app.ShowPrompt("Enter shape vertex(Reset to create Form)"); app.CommandState.StartDynamics(); } } }
public void Dynamics(ref Point3d Point, BCOM.View View, MsdDrawingMode DrawMode) { int nCnt; Point3d[] ptTemp = null; BCOM.Application app = Utilities.ComApp;
if (m_nIndex == 1) { LineElement eleLine;
nCnt = m_ptSlab.Length; Array.Resize<Point3d>(ref ptTemp, nCnt + 1); m_ptSlab.CopyTo(ptTemp, 0); ptTemp[nCnt] = Point;
eleLine = app.CreateLineElement1(null, ptTemp); eleLine.Redraw(DrawMode); } else if (m_nIndex > 1) { ShapeElement eleShape;
eleShape = app.CreateShapeElement1(null, ptTemp, MsdFillMode.NotFilled); eleShape.Redraw(DrawMode); } }
public void Keyin(string Keyin) { }
public void Reset() { PlateForm myPlateForm = null; BCOM.Application app = Utilities.ComApp;
try { foreach (Form myForm in System.Windows.Forms.Application.OpenForms) if ("PlateForm" == myForm.Name) { myPlateForm = (PlateForm)myForm; break; }
app.CommandState.StopDynamics();
m_bStop = true;
if (m_nIndex > 2) { int nType = 0; double dThickness; double dSideAngle; string strType; Point3d ptNormal = app.Point3dFromXYZ(0,0,0); ShapeElement eleShape;
TFFormRecipe tfRecipe;
eleShape = app.CreateShapeElement1(null, ref m_ptSlab, MsdFillMode.NotFilled); if (eleShape != null) { if (eleShape.IsPlanar) { ptNormal = eleShape.Normal; } } dThickness = Convert.ToDouble(myPlateForm.txtThickness.Text); // Slab Thickness if (myPlateForm.txtRotation.Text.ToString() == "") dSideAngle = 0; else dSideAngle = Convert.ToDouble(myPlateForm.txtRotation.Text); // Side Angle strType = myPlateForm.cmbSideAngle.Text.ToString();
if (string.Compare(strType, "Angle") == 0) { nType = (int)TFdSlabFormSideInclinationType.tfdSlabFormSideInclinationTypeAngle; } else if (string.Compare(strType, "Horizontal") == 0) { nType = (int)TFdSlabFormSideInclinationType.tfdSlabFormSideInclinationTypeHorizontal; } else if (string.Compare(strType, "Vertical") == 0) { nType = (int)TFdSlabFormSideInclinationType.tfdSlabFormSideInclinationTypeVertical; }
// Create Slab Form tfRecipe = fn_MakeSlabForm(m_ptSlab, nType, dSideAngle, ptNormal, dThickness);
}
m_nIndex = 0; m_bStop = false;
//app.GetCExpressionValue("mdlState_clear()"); //app.ShowCommand(""); app.CommandState.StartDefaultCommand();
} catch (Exception ex) { m_nIndex = 0; m_bStop = false; app.CommandState.StopDynamics(); mdlState_clear(); app.CommandState.StartDefaultCommand();
MessageBox.Show("Error: " + ex.Message, "Reset Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public void Start() { BCOM.Application app = Utilities.ComApp; m_nIndex = 0; m_bStop = false; Array.Resize<Point3d>(ref m_ptSlab, 1);
app.CommandState.EnableAccuSnap();
app.ShowCommand("Place Slab Form"); app.ShowPrompt("Enter shape vertex"); }
// Create Slab Form private TFFormRecipe fn_MakeSlabForm(Point3d[] ptBaseArray, int nType, double dSideAngle, Point3d ptNormal, double dThickness) { int i; TFFormRecipe tfFormRecipe = null; TFFormRecipeSlabListClass tfSlabCls = new TFFormRecipeSlabListClass();
try { BTF.TFApplicationList tfAppList = new BTF.TFApplicationList(); BTF.TFApplication tfApp = tfAppList.TFApplication; BCOM.Application app = Utilities.ComApp;
int[] nInclinationType = null; // TFdSlabFormSideInclinationType을 저장할 배열 double[] dInclination = null; // Side angle을 저장할 배열 ModelReference modRef = null;
if (ptBaseArray.Length > 2) { Array.Resize<int>(ref nInclinationType, ptBaseArray.Length); Array.Resize<double>(ref dInclination, ptBaseArray.Length);
for (i = 0; i < ptBaseArray.Length; i++) { nInclinationType[i] = nType;
if (nType == 0) dInclination[i] = dSideAngle; else dInclination[i] = 0.0; }
if (dSideAngle >= 0) { tfSlabCls.Init(); tfSlabCls.InitFromPoints(ref ptBaseArray, ref nInclinationType, ref dInclination, ref ptNormal, dThickness, true, TFdTriformaObjectDisplayMode.tfdTriformaObjectDisplayModeFaces, null); } else { tfSlabCls.Init(); tfSlabCls.InitFromPoints(ref ptBaseArray, ref nInclinationType, ref dInclination, ref ptNormal, dThickness, false, TFdTriformaObjectDisplayMode.tfdTriformaObjectDisplayModeFaces, null); }
tfSlabCls.SetColor(3); tfSlabCls.SetWeight(0); tfSlabCls.SetPartFamilyName("Primary Beams"); tfSlabCls.SetPartName("Steel"); tfSlabCls.Synchronize(); modRef = app.ActiveModelReference; tfFormRecipe = tfSlabCls.AsTFFormRecipe; tfApp.ModelReferenceAddFormRecipe(modRef, ref tfFormRecipe); } else { MessageBox.Show("Slab Form Fail", "fn_MakeSlabForm Error", MessageBoxButtons.OK, MessageBoxIcon.Information); }
} catch (Exception ex) { MessageBox.Show("Error: " + ex.Message, "fn_MakeSlabForm Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
return tfFormRecipe; }
private void fn_AddPointToPoint3D(ref Point3d[] ptPoint, Point3d ptAdd, int nArrayCnt) { int nSize;
try { nSize = ptPoint.Length; // array size if (nArrayCnt > nSize) { Array.Resize<Point3d>(ref ptPoint, nArrayCnt); } ptPoint[nArrayCnt -1] = ptAdd; } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message, "fn_AddPointFromPoint3D Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
Is this code running in AECOSim or is it a seperate .exe ?
Regards,
mark anderson [Bentley]
Visit me at https://communities.bentley.com/communities/other_communities/bentley_innovation/default.aspx