.NET

Reply
Valued Contributor
kevinsir
Posts: 78
Registered: ‎08-20-2012
Message 11 of 19 (111 Views)

Re: How can I use a graphic ellipse with text together?

03-17-2013 07:33 AM in reply to: Hallex

Thanks very much for your help ! I will try it !

Valued Contributor
kevinsir
Posts: 78
Registered: ‎08-20-2012
Message 12 of 19 (98 Views)

Re: How can I use a graphic ellipse with text together?

03-18-2013 07:27 AM in reply to: kevinsir

Very greatful,Now I have another question.Is there any method to  access the AttributeDefinition or the ellipse of the block after having inserted the block into the paper. I want to set  AttributeDefinition visible or invisible dynamicly by code! 

Moderator
Alexander.Rivilis
Posts: 1,412
Registered: ‎04-09-2008
Message 13 of 19 (94 Views)

Re: How can I use a graphic ellipse with text together?

03-18-2013 08:14 AM in reply to: kevinsir

kevinsir wrote:

... I want to set  AttributeDefinition visible or invisible dynamicly by code!  ...


AttributeDefinition or AttributeReference? AttributeDefinition is one for all BlockReference, but AttributeReference can be individual in every BlockReference.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 14 of 19 (89 Views)

Re: How can I use a graphic ellipse with text together?

03-18-2013 11:02 AM in reply to: kevinsir

You can set attribute invisible by click on attribute after insrting a block

here is quick example

   <CommandMethod("avis")> _
        Public Shared Sub SetAttributeVisibility()
            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

            Dim ed As Editor = doc.Editor

            Dim db As Database = doc.Database

            Dim ucs As Matrix3d = ed.CurrentUserCoordinateSystem

            Dim pno As New PromptNestedEntityOptions(vbLf & "Select an attribute inside an INSERT: ")

            Dim nres As PromptNestedEntityResult = ed.GetNestedEntity(pno)

            If nres.Status <> PromptStatus.OK Then
                ed.WriteMessage(vbLf & "Entsel failed")
                Return
            End If

            Try
                Dim tr As Transaction = db.TransactionManager.StartTransaction()

                Using tr
                    Dim pickPt As Point3d = nres.PickedPoint.TransformBy(ucs)

                    ed.WriteMessage(vbLf & "Picked point is {0}", pickPt)

                    Dim selId As ObjectId = nres.ObjectId

                    Dim objIds As New List(Of ObjectId)(nres.GetContainers())

                    ' Reverse the "containers" list

                    ' Now append the selected entity

                    objIds.Add(selId)

                    objIds.Reverse()

                    ' Retrieve the sub-entity path for this entity

                    Dim subEnt As New SubentityId(SubentityType.Null, 0)

                    Dim path As New FullSubentityPath(objIds.ToArray(), subEnt)

                    ' Open the outermost container, relying on the open

                    ' transaction...

                    Dim pSubEnt As Entity = TryCast(tr.GetObject(objIds(0), OpenMode.ForRead, False), Entity)

                    If Not pSubEnt.ObjectId.ObjectClass.IsDerivedFrom(RXClass.GetClass(GetType(AttributeReference))) Then Return

                    Dim attRef As AttributeReference = TryCast(tr.GetObject(pSubEnt.ObjectId, OpenMode.ForRead, False), AttributeReference)

                    If attRef Is Nothing Then Return

                    If attRef.Visible Then

                        ' ed.WriteMessage(vbLf & "The sub entity is of type {0}", pSubEnt.GetType().Name)

                        ' Get the object id of the owner block

                        Dim mainId As ObjectId = pSubEnt.OwnerId

                        Dim pOwner As DBObject = TryCast(tr.GetObject(mainId, OpenMode.ForRead, False), DBObject)

                        ' Output the class name of the owner block

                        ed.WriteMessage(vbLf & "The owner is of type {0}", pOwner.[GetType]().Name)

                        Dim pBlkName As String = String.Empty

                        ' Output the information of the block definition

                        Dim pBTR As BlockTableRecord = TryCast(pOwner, BlockTableRecord)

                        If pBTR IsNot Nothing Then

                            pBlkName = pBTR.Name

                            ed.WriteMessage(vbLf & "Block Record name is {0}", pBlkName)
                        End If
                        Dim pBref As BlockReference = TryCast(pOwner, BlockReference)
                        If pBref Is Nothing Then Return
                        pBref.UpgradeOpen()
                        attRef.UpgradeOpen()
                        attRef.Visible = False
                    End If

                    tr.Commit()
                End Using
            Catch ex As Autodesk.AutoCAD.Runtime.Exception
                ed.WriteMessage((vbLf + ex.Message & vbLf) + ex.StackTrace)

            Finally
            End Try
        End Sub

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Contributor
kevinsir
Posts: 78
Registered: ‎08-20-2012
Message 15 of 19 (74 Views)

Re: How can I use a graphic ellipse with text together?

03-19-2013 02:03 AM in reply to: Alexander.Rivilis
I am sorry that I mean the AttributeReference! Now I have find the 'AttributeCollection' Property of BlockReference which can access the Attribute. However, I have not find any Property of BlockReference to access the ellipse. Does it have any way to access it and set it visible or invisible?
Moderator
Alexander.Rivilis
Posts: 1,412
Registered: ‎04-09-2008
Message 16 of 19 (69 Views)

Re: How can I use a graphic ellipse with text together?

03-19-2013 04:31 AM in reply to: kevinsir

kevinsir wrote:
...However, I have not find any Property of BlockReference to access the ellipse. Does it have any way to access it and set it visible or invisible?...

Ellipse is a part of BlockTableRecord and not part of BlockReference. You can have access to ellipse in BlockTableRecord and set it visible or invisible. But that setting will effect ALL BlockReference created from this BlockTableRecord (after regeneration of drawing).  If you create dynamic block you can manipulate property Visibility to hide/unhide ellipse and text individually in each BlockReference. Look at attached dwg-file.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Valued Contributor
kevinsir
Posts: 78
Registered: ‎08-20-2012
Message 17 of 19 (63 Views)

Re: How can I use a graphic ellipse with text together?

03-19-2013 07:18 PM in reply to: kevinsir

Aha,maybe dynamic block is which I needed。Thanks very much。I will try this way ! If your can give me some code for controlling dynamic block of C#,that will be perfect!

Valued Contributor
kevinsir
Posts: 78
Registered: ‎08-20-2012
Message 18 of 19 (59 Views)

Re: How can I use a graphic ellipse with text together?

03-19-2013 10:12 PM in reply to: kevinsir

I am sorry that I have taken some time on the dynamic block .Howerver, there is a problem that how can I change the DBText 'test'  on your  attachment  ? I only have found a way to change it when  the block is defining. I try to create a new attribute when defining, but it is not shown on the paper.

Valued Contributor
kevinsir
Posts: 78
Registered: ‎08-20-2012
Message 19 of 19 (52 Views)

Re: How can I use a graphic ellipse with text together?

03-20-2013 03:38 AM in reply to: kevinsir

I am so sorry that I have soloved the problem! I have not set the default vale . Thanks for all repies!

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.