GstarCAD เป็น CAD จีนที่ ราคาไม่แพง เล็ก เร็ว 64bits ด้วย การเขียนโปรแกรม บน dotnet ทำได้เหมือนกับ Autocad โดยที่ GstarCAD 2017 (http://www.gstarcad.net) จะมี API แบบเดียวกับ Autocad 2012
โดยที่ จะต้อง reference Dll 2 ตัว
ได้แก่ GMAP.dll และ GMDB.dll แล้ว (แทน acmgd.dll ,acmdb.dll)
แก้ Using
จาก Autodesk.Autocad.. -> GRxCAD...
ก็จะ compile ได้ และ เลือก เป็น Dotnet 4 (Autocad เป็น 3.5)
เรียก netload เหมือน Autocad เรียกคำสั่งเดียวกัน
วันพุธที่ 11 มกราคม พ.ศ. 2560
วันจันทร์ที่ 9 มกราคม พ.ศ. 2560
autocad 2011-12 load โปรแกรม dotnet 4 สำหรับ Visual Studio 2013-15
Autocad 2011-12 พัฒนาบน Dotnet3.5 จะ Load โปรแกรมบางตัวไม่ได้ ที่ ต้อง Load Dotnet 4.0
สามารถ ทำได้ โดย แก้ที่ acad.exe.config
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
<!--All assemblies in AutoCAD are fully trusted so there's no point generating publisher evidence-->
<runtime>
<generatePublisherEvidence enabled="false"/>
</runtime>
</configuration>
สามารถ ทำได้ โดย แก้ที่ acad.exe.config
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
<!--All assemblies in AutoCAD are fully trusted so there's no point generating publisher evidence-->
<runtime>
<generatePublisherEvidence enabled="false"/>
</runtime>
</configuration>
วันอังคารที่ 13 ธันวาคม พ.ศ. 2559
Revit API MessageBox จาก TaskDialog
TaskDialog ถ้าไม่มี Option อะไรเลย จะเป็น Message ธรรมดา
TaskDialog.Show("Title","Message");
จะมีแค่ ปิด Dialog เท่านั้น
กรณีต้องการ "Yes", "No"
ให้เพิ่ม
TaskDialog.Show("Title","Message");
จะมีแค่ ปิด Dialog เท่านั้น
กรณีต้องการ "Yes", "No"
ให้เพิ่ม
TaskDialogResult tdr= TaskDialog.Show("วัตถุนี้เป็น Link!", "ตอบ (Yes) หรือ (No)", TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.No);
TaskDialog.Show("??",tdr.ToString());
จะได้ผล เป็น "Yes" หรือ "No"
และถ้าต้องการหลายๆ ทางเลือก
ลอง แบบนี้
TaskDialog td = new TaskDialog("Decision");
td.MainContent = "What do you want to do?";
td.AddCommandLink(TaskDialogCommandLinkId.CommandLink1,
"Use Simple Insertion Point",
"This option works for free-floating items");
td.AddCommandLink(TaskDialogCommandLinkId.CommandLink2,
"Use Face Reference",
"Use this option to place the family on a wall or other surface");
switch (td.Show())
{
case TaskDialogResult.CommandLink1:
// do the simple stuff
break;
case TaskDialogResult.CommandLink2:
// do the face reference
break;
default:
// handle any other case.
break;
}
วันจันทร์ที่ 12 ธันวาคม พ.ศ. 2559
C# MessageBox Input Show Grid แบบง่ายๆ
ต้องการ Message Box Input แบบง่ายๆ ไม่ต้องการสร้าง Form ต่อ ท้าย ใน Class ที่กำลังทำอยู่
เวลาเรียกใช้ ก็
String ins=InputPrompt.ShowDialog("Hello","Question"," default");
เวลาเรียกใช้ ก็
String ins=InputPrompt.ShowDialog("Hello","Question"," default");
public static class InputPrompt
{
public static string ShowDialog(string text, string caption,string defText)
{
Form prompt = new Form()
{
Width = 500,
Height = 150,
FormBorderStyle = FormBorderStyle.FixedSingle,
Text = caption,
StartPosition = FormStartPosition.CenterScreen
};
Label textLabel = new Label() { Left = 50, Top = 20, Text = text };
TextBox textBox = new TextBox() { Left = 50, Top = 50, Width = 400 };
Button confirmation = new Button() { Text = "Ok", Left = 350, Width = 100, Top = 70, DialogResult = DialogResult.OK };
confirmation.Click += (sender, e) => { prompt.Close(); };
prompt.Controls.Add(textBox);
prompt.Controls.Add(confirmation);
prompt.Controls.Add(textLabel);
prompt.AcceptButton = confirmation;
if (defText != null) textBox.Text = defText;
return prompt.ShowDialog() == DialogResult.OK ? textBox.Text : "";
}
}
เพิ่มสำหรับ แสดง DataTable บน DataGridView
เพิ่มสำหรับ แสดง DataTable บน DataGridView
public static string GridDialog(string caption, object dt)
{
System.Windows.Forms.Form prompt = new System.Windows.Forms.Form()
{
Width = 500,
Height = 500,
FormBorderStyle = FormBorderStyle.FixedSingle,
Text = caption,
StartPosition = FormStartPosition.CenterScreen,
AutoSizeMode=AutoSizeMode.GrowAndShrink
};
DataGridView dv = new DataGridView() { Left = 1, Top = 1, Width = 400,Height =400 };
Button confirmation = new Button() { Text = "Ok", Left = 350, Width = 100, Top = 70, DialogResult = DialogResult.OK };
//Anchor: Top,Left
//AutoSizeColumn: Fill
//Dock: Fill
dv.Dock = DockStyle.Fill;
dv.AutoSize = true;
dv.Anchor = AnchorStyles.Top | AnchorStyles.Left;
prompt.Controls.Add(dv);
prompt.Controls.Add(confirmation);
prompt.AcceptButton = confirmation;
dv.DataSource = dt; // can be datatable , List
prompt.ShowDialog();
return"";
}
// ในกรณี Linq ต้องการแสดงผลบน Grid ต้องใส่ toList() ด้วย
// ในกรณี Linq ต้องการแสดงผลบน Grid ต้องใส่ toList() ด้วย
var result = dt.Rows.Cast<DataRow>()
.Select(row=> new{ key= row["BomID"].ToString(),data= row["ChildID"].ToString()}).ToList();
วันศุกร์ที่ 11 พฤศจิกายน พ.ศ. 2559
Revit API แปลง Units
แปลงจาก ฟุต เป็น เมตร
double asMeter = UnitUtils.Convert(cl.Width, DisplayUnitType.DUT_DECIMAL_FEET, DisplayUnitType.DUT_METERS);
แสดง Unit ปัจจุบันใน Document
Units units = doc.GetUnits();
string outStr = "";
IList<UnitType> unitTypes = UnitUtils.GetValidUnitTypes();
uL= unitTypes.Where(x => x.ToString() == "UT_Length").First();
FormatOptions fmtOpts = units.GetFormatOptions(ut);
string du = fmtOpts.DisplayUnits.ToString();
วันศุกร์ที่ 4 พฤศจิกายน พ.ศ. 2559
การอ่านค่าจาก Schedule API ใน Revit
Schedule API เป็น ส่วนที่เพิ่มเติมมาใหม่ใน Revit API 2014 โดยที่ผู้ใช้งาน สามารถ อ่านค่า จาก View มาได้ ทั้งชื่อชอง View และ Table ของ ตาราง
ViewSchedule จะเป็น class ลูกจาก View โดยตารางจะอยู่ใน TableData ข้อมูล จะอยู่ใน
ชื่ออยู่ใน currentView.Name
SectionType.Body
ตัวอย่างนี้ จะออกเป็น CSV format
ViewSchedule จะเป็น class ลูกจาก View โดยตารางจะอยู่ใน TableData ข้อมูล จะอยู่ใน
ชื่ออยู่ใน currentView.Name
SectionType.Body
ตัวอย่างนี้ จะออกเป็น CSV format
View currentView = uDoc.ActiveView;
string vName = currentView.Name; // Schedule name
ViewSchedule vs = currentView as ViewSchedule;
TableData vd = vs.GetTableData();
TableSectionData tds = vd.GetSectionData(SectionType.Body);
int rCount = tds.NumberOfRows;
int rCol = tds.NumberOfColumns;
string allSchAll = "";
for (int i = 0; i < rCount; i++)
{
string sLine = "";
for (int j = 0; j < rCol; j++)
{
sLine += tds.GetCellText(i, j)+",";
}
allSchAll += sLine;
}
TaskDialog.Show("data", allSchAll);
วันพฤหัสบดีที่ 3 พฤศจิกายน พ.ศ. 2559
การสร้าง Form ใน DDD ใน Revit
กรณีที่ต้องการ Form ของ c# ใน Revit ของ DDD ทำได้โดยการ Mouse ขวา และ Add Form ใหม่เข้าไปใน Solution
สร้าง Form โดย double click ที่ Form แล้ว Design ตามใจ
แล้วใน โปรแกรม หลัก ของ การเรียกเช่น Class1.cs
เพิ่ม Method ที่จะเรียก (callElemCat เป็นสมมติ)
หลังบรรทัด
using...
ให้เติม ชื่อของ Form ตามนี้ และ ใส่ .Designer.cs ด้วย
เรียก DDD ใน Revit ก็ได้ Form
กรณีที่ จะให้ Form มี คำสั่ง ของ Revit ก็ using Autodesk.Revit... ตามปรกติ
สร้าง Form โดย double click ที่ Form แล้ว Design ตามใจ
แล้วใน โปรแกรม หลัก ของ การเรียกเช่น Class1.cs
เพิ่ม Method ที่จะเรียก (callElemCat เป็นสมมติ)
หลังบรรทัด
using...
ให้เติม ชื่อของ Form ตามนี้ และ ใส่ .Designer.cs ด้วย
//css_import elemCatForm1.cs
//css_import elemCatForm1.Designer.cs
namespace RevitHello
{
public class Class1
{
// คำสั่งที่จะเรียกอยู่ที่นี้
public static void callElemCat(ExternalCommandData commandData)
{
elemCatForm1 myform = new elemCatForm1();
if (myform.ShowDialog == System.Windows.Forms.DialogResult.OK)
{
// ..process here
}
}
// จบคำสั่ง
เรียก DDD ใน Revit ก็ได้ Form
กรณีที่ จะให้ Form มี คำสั่ง ของ Revit ก็ using Autodesk.Revit... ตามปรกติ
สมัครสมาชิก:
บทความ (Atom)



