.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to identify an object in order to update its property C#

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Raymond.Le
609 Views, 3 Replies

How to identify an object in order to update its property C#

 

I draw a print in AutoCAD with 200 circles containing 200  Multileaders   with text "XXX To A" where XXX is actually distance to Datum A.  I know the design will be fixed but I will need to update these 200 x "XXX" every time the customer comes up with something new. My idea is to create a datagridview table or direct import Excel file to update these 200 x "XXX". 

 

My approach:

1. Create a data table as user input or using Excel as input --> contains 200 x "XXX" ----> this is not the issue

 

2. Create 200 x Multileaders with text "XXX", then associate their text property with some ID ---> like txtS001, txtS002, txtS003..txtS200.. and do

 

txtS001.Text = (string)new_value;

 

3. Loop through the datagridview or Excel file to make the update

 

How can I associate an object's property/attributes to manageable ID as reference? And if there is any sample code to make the update

 

 

 

Tags (1)
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: Raymond.Le

Step 1: create a table in your acad drawing. I use a table with 2 columns: first col is the description of the field, second column is the actual field.

step 2: assign each dimension to a cell in the table (from col 2). Use field-  formula, then click on the table cell you want to assign to.

Now if you manually change the value in the table and do a refresh, dimension will get updated with value from table.

 

 

 

acad_table.jpg

 

Step 3:

The code is in vb.net but you can easily convert it to c#

Value() is an array of values from excel or where ever you have the 200 values

 

Public Sub PopulateCalcDataTable(ByVal LayoutName As String, ByVal Value() As String)

Dim acLayouts As AcadLayouts
Dim acEntity As AcadEntity

 

AcadDrawing.ActiveSpace = AcActiveSpace.acPaperSpace
acLayouts = AcadDrawing.Layouts
AcadDrawing.ActiveLayout = AcadDrawing.Layouts.Item(LayoutName)
For Each acEntity In AcadDrawing.PaperSpace
If acEntity.ObjectName = "AcDbTable" AndAlso
acEntity.GetText(0, 0) = "Calc Data" Then
For index As Integer = LBound(Value) To UBound(Value)
If Value(index) = "--" Or Value(index) = "--'" Then
Value(index) = "0" 
End If
acEntity.SetText(index + 1, 1, Value(index))
Next
End If
Next

End Sub

 

 

 

 

 

Message 3 of 4
Raymond.Le
in reply to: Raymond.Le

Thanks, I asked another question in normal AutoCAD forum and I got the answer, the List will return the HandleID as  I can use to point to the object

Message 4 of 4
ActivistInvestor
in reply to: Anonymous


@Anonymous wrote:

Step 1: create a table in your acad drawing. I use a table with 2 columns: first col is the description of the field, second column is the actual field.

step 2: assign each dimension to a cell in the table (from col 2). Use field-  formula, then click on the table cell you want to assign to.

Now if you manually change the value in the table and do a refresh, dimension will get updated with value from table.

 

 

 

 

Step 3:

The code is in vb.net but you can easily convert it to c#

Value() is an array of values from excel or where ever you have the 200 values

 

Public Sub PopulateCalcDataTable(ByVal LayoutName As String, ByVal Value() As String)

Dim acLayouts As AcadLayouts
Dim acEntity As AcadEntity

 

AcadDrawing.ActiveSpace = AcActiveSpace.acPaperSpace
acLayouts = AcadDrawing.Layouts
AcadDrawing.ActiveLayout = AcadDrawing.Layouts.Item(LayoutName)
For Each acEntity In AcadDrawing.PaperSpace
If acEntity.ObjectName = "AcDbTable" AndAlso
acEntity.GetText(0, 0) = "Calc Data" Then
For index As Integer = LBound(Value) To UBound(Value)
If Value(index) = "--" Or Value(index) = "--'" Then
Value(index) = "0" 
End If
acEntity.SetText(index + 1, 1, Value(index))
Next
End If
Next

End Sub

 

 

 

 

 


Just don't insert/delete columns or rows to the left of/above the referenced cell in the table afterward.

 

It seems someone didn't think that one out, because references to cells should be able to survive those operations.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report