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

last block instered example

3 REPLIES 3
Reply
Message 1 of 4
JeffatSJE
612 Views, 3 Replies

last block instered example

Is there any examples that show how to get the last block inserted and update its attributes using Csharp?

Thanks
Jeff
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: JeffatSJE

I think you need to be more specific.

The 'last block inserted' when? In the current session, or
in a previous session?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6299037@discussion.autodesk.com...
Is there any examples that show how to get the last block inserted and
update its attributes using Csharp?

Thanks
Jeff
Message 3 of 4
JeffatSJE
in reply to: JeffatSJE

current session. The block all ready exists somewhere in the system path.

I found these examples in VBA which I currently use but do to the lack of a VBA interface in 2010 I am trying to quickly move my VBA apps over to C#

Function lastenthandle() As String
Dim entity As AcadObject
Dim count As Variant
' set count to all items in modelspace collection
count = ThisDrawing.ModelSpace.count
Set entity = ThisDrawing.ModelSpace.Item(count - 1)
' check if entity is a block if not count down until it is
While count > 0
If StrComp(entity.EntityName, "AcDbBlockReference", 1) = 0 Then
If entity.HasAttributes Then
lastenthandle = entity.handle
Exit Function
End If
End If
count = count - 1
Set entity = ThisDrawing.ModelSpace.Item(count)
Wend
End Function

Function enttagnam(ByVal Enthandle As String) As String
Dim ourblock As AcadObject
' Get the attributes for the block reference
Dim varAttributes As Variant
Set ourblock = ThisDrawing.HandleToObject(Enthandle)
varAttributes = ourblock.GetAttributes
' Move the attribute tags and values into a string to be displayed in a Msgbox
Dim strAttributes As String
Dim i As Integer
For i = LBound(varAttributes) To UBound(varAttributes)
If varAttributes(i).TagString = "TAG" Or varAttributes(i).TagString = "TAG1" Then
enttagnam = varAttributes(i).TextString
'MsgBox "The TAG attribute for blockReference " & ourblock.Name & " are: " & enttagnam, , "GetAttributes Example"
End If
Next
End Function




Thanks
J.


AutoCAD 2010 64bit
Message 4 of 4
Anonymous
in reply to: JeffatSJE

I'm afraid this will not work in .NET the way it worked in VBA, mainly
because in the managed API, you cannot access items in blocks using numeric
indexes.

If you are in a hurry to port, my advice would be to use the COM API from C#
or VB.NET to do the same thing you were doing in VBA.

You can do the other part in managed code by getting the managed wrapper for
the AcadBlockReference COM object using the DBObject.FromAcadObject() static
method .

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6299383@discussion.autodesk.com...
current session. The block all ready exists somewhere in the system path.

I found these examples in VBA which I currently use but do to the lack of a
VBA interface in 2010 I am trying to quickly move my VBA apps over to C#

Function lastenthandle() As String
Dim entity As AcadObject
Dim count As Variant
' set count to all items in modelspace collection
count = ThisDrawing.ModelSpace.count
Set entity = ThisDrawing.ModelSpace.Item(count - 1)
' check if entity is a block if not count down until it is
While count > 0
If StrComp(entity.EntityName, "AcDbBlockReference", 1) = 0 Then
If entity.HasAttributes Then
lastenthandle = entity.handle
Exit Function
End If
End If
count = count - 1
Set entity = ThisDrawing.ModelSpace.Item(count)
Wend
End Function

Function enttagnam(ByVal Enthandle As String) As String
Dim ourblock As AcadObject
' Get the attributes for the block reference
Dim varAttributes As Variant
Set ourblock = ThisDrawing.HandleToObject(Enthandle)
varAttributes = ourblock.GetAttributes
' Move the attribute tags and values into a string to be displayed in a
Msgbox
Dim strAttributes As String
Dim i As Integer
For i = LBound(varAttributes) To UBound(varAttributes)
If varAttributes(i).TagString = "TAG" Or varAttributes(i).TagString
= "TAG1" Then
enttagnam = varAttributes(i).TextString
'MsgBox "The TAG attribute for blockReference " & ourblock.Name
& " are: " & enttagnam, , "GetAttributes Example"
End If
Next
End Function




Thanks
J.


AutoCAD 2010 64bit

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost