Author Topic: i ❤ attributes  (Read 494 times)

0 Members and 1 Guest are viewing this topic.

poncelet

  • Newt
  • Posts: 51
i ❤ attributes
« on: April 28, 2012, 09:52:25 am »
Hi all. Ok i create a block (OrionPoint) and a simple attribute (The id of the point eg: 1, 2, 3, 4...)

The create block method:
Code - vb.net: [Select]
  1.    Public Sub Create()
  2.        If Me.Exist = True Then Return
  3.  
  4.        Using dLock As DocumentLock = doc.LockDocument
  5.            Using trans As Transaction = db.TransactionManager.StartTransaction()
  6.                'get the block table
  7.                Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForWrite)
  8.  
  9.                'create new block table record
  10.                Dim btr As New BlockTableRecord()
  11.                btr.Name = "OrionPoint"
  12.                Dim btrId As ObjectId = bt.Add(btr)
  13.                trans.AddNewlyCreatedDBObject(btr, True)
  14.  
  15.                'create a circle for the outer boundary of the hatch
  16.                Dim circ As Circle = New Circle()
  17.                circ.Center = New Point3d(0, 0, 0)
  18.                circ.Radius = 0.0005 * SCALE_FACTOR
  19.                circ.LineWeight = LineWeight.LineWeight009
  20.  
  21.                'add the circle object to the block table record
  22.                btr.AppendEntity(circ)
  23.                trans.AddNewlyCreatedDBObject(circ, True)
  24.  
  25.                'adds the circle to object id array
  26.                Dim oc As ObjectIdCollection = New ObjectIdCollection()
  27.                oc.Add(circ.ObjectId)
  28.  
  29.                'create the hatch and append it to the block table record
  30.                Dim h As Hatch = New Hatch()
  31.                oc.Add(btr.AppendEntity(h))
  32.                trans.AddNewlyCreatedDBObject(h, True)
  33.  
  34.                'properties of the hatch
  35.                h.SetHatchPattern(HatchPatternType.PreDefined, "SOLID")
  36.                h.Associative = False
  37.                h.AppendLoop(HatchLoopTypes.Outermost, oc)
  38.                h.EvaluateHatch(True)
  39.                h.Color = Color.FromRgb(255, 255, 255)
  40.  
  41.                Dim dot As DrawOrderTable = trans.GetObject(btr.DrawOrderTableId, OpenMode.ForWrite)
  42.                dot.SwapOrder(oc.Item(0), oc.Item(1)) 'item 0 = circ, item 1 = hatch
  43.  
  44.                'create an attribute definition
  45.                Dim ad As New AttributeDefinition
  46.                ad.Prompt = "Insert ID"
  47.                ad.Tag = "ID"
  48.                ad.TextString = "Point ID"
  49.                ad.Justify = AttachmentPoint.MiddleLeft
  50.                ad.AlignmentPoint = New Point3d(0.001 * SCALE_FACTOR, 0, 0)
  51.                ad.Preset = False
  52.                ad.Height = TEXT_HEIGHT
  53.                btr.AppendEntity(ad)
  54.                trans.AddNewlyCreatedDBObject(ad, True)
  55.  
  56.                trans.Commit()
  57.            End Using
  58.        End Using
  59.  
  60.    End Sub

I struggle for hours to add the brockreference (that's easy) and give the attribute (that isn't) the id (1, 2, 3...).

Thank you
Ce que femme veut, Dieu le veut.

Kerry

  • Mesozoic Relic
  • Needs a day job
  • Posts: 9646
  • class keyThumper<T>:ILazy<T>
Re: i ❤ attributes
« Reply #1 on: April 28, 2012, 05:10:00 pm »

Code - vb.net: [Select]
  1. If Me.Exist = True Then Return

What is Me ?

and what is .Exist  ??


Regards
Kerry
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline : absolutely none at all.

--> Donate to TheSwamp <--

gile

  • Water Moccasin
  • Posts: 1590
  • Marseille, France
Re: i ❤ attributes
« Reply #2 on: April 28, 2012, 05:42:33 pm »
Me (VB) = this (C#)
Speaking English as a French Frog

Kerry

  • Mesozoic Relic
  • Needs a day job
  • Posts: 9646
  • class keyThumper<T>:ILazy<T>
Re: i ❤ attributes
« Reply #3 on: April 28, 2012, 05:53:12 pm »
Yes, I know that gile.

but what is Me ? what sort of object ? .. where is it defined ?
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline : absolutely none at all.

--> Donate to TheSwamp <--

BlackBox

  • Water Moccasin
  • Posts: 2248
Re: i ❤ attributes
« Reply #4 on: April 28, 2012, 09:06:43 pm »
Whatever it (me) is cannot be good, as the If statement immediately Returns if it Exists (... in a Sub, not a Function?  :?  ).
"Potential has a shelf life." - Margaret Atwood

whoknows

  • Newt
  • Posts: 68
Re: i ❤ attributes
« Reply #5 on: April 28, 2012, 10:16:37 pm »
Code - vb.net: [Select]
  1. If Me.Exist = True Then Return
In this case does not appear to have importance.

"Me "and "This" It is always redundant.

About "Exist" and VB.NET:
Code - vb.net: [Select]
  1. Public Class Exist_Prop
  2.    Private _exist As Boolean
  3.   ' All this can be compiled
  4.   ' Public Property Exist() As Boolean
  5.    Public Property Exist As Boolean
  6.        Get
  7.            Return _exist
  8.        End Get
  9.        Set(ByVal Value As Boolean)
  10.            _exist = Value
  11.        End Set
  12.    End Property
  13.  
  14.    Public Sub Create()
  15.        If Me.Exist Then
  16.            Return
  17.        End If
  18.    End Sub
  19. End Class
  20.  
  21. Public Class Exist_Func
  22.    Public Function Exist() As Boolean
  23.        Return True
  24.    End Function
  25.  
  26.    Public Sub Create()
  27.        ' All this can be compiled
  28.        ' If Exist () Then
  29.        If Me.Exist Then
  30.            Return
  31.        End If
  32.    End Sub
  33. End Class
  34.  
  35.  
That's all folks

Kerry

  • Mesozoic Relic
  • Needs a day job
  • Posts: 9646
  • class keyThumper<T>:ILazy<T>
Re: i ❤ attributes
« Reply #6 on: April 28, 2012, 11:06:02 pm »

:)

Thanks for the lesson whoknows
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline : absolutely none at all.

--> Donate to TheSwamp <--

whoknows

  • Newt
  • Posts: 68
Re: i ❤ attributes
« Reply #7 on: April 28, 2012, 11:23:01 pm »

:)

Thanks for the lesson whoknows
lesson???? No, this is just my opinion about "Exist", "Me" & "this".
That's all folks

poncelet

  • Newt
  • Posts: 51
Re: i ❤ attributes
« Reply #8 on: April 29, 2012, 04:41:29 am »
Me.exist

Code - vb.net: [Select]
  1.    Private Function Exist() As Boolean
  2.  
  3.        Using trans As Transaction = db.TransactionManager.StartTransaction()
  4.  
  5.            Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead)
  6.            If bt.Has("OrionPoint") Then
  7.                Return True
  8.            Else
  9.                Return False
  10.            End If
  11.        End Using
  12.  
  13.    End Function

Class members so far
Code - vb.net: [Select]
  1. Public Class OrionPoint
  2.  
  3.    Public Sub Create()
  4.  
  5.    Private Function Exist() As Boolean
  6.  
  7. End Class
« Last Edit: April 29, 2012, 04:45:09 am by poncelet »
Ce que femme veut, Dieu le veut.

Kerry

  • Mesozoic Relic
  • Needs a day job
  • Posts: 9646
  • class keyThumper<T>:ILazy<T>
Re: i ❤ attributes
« Reply #9 on: April 29, 2012, 04:49:45 am »
See, wouldn't it have been less confusing to post it all at the start .. even though your naming is still a little confusing.
wouldn't
If (Exist()) work ?

now, what was your question ?
« Last Edit: April 29, 2012, 04:53:06 am by Kerry »
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline : absolutely none at all.

--> Donate to TheSwamp <--

poncelet

  • Newt
  • Posts: 51
Re: i ❤ attributes
« Reply #10 on: April 29, 2012, 04:55:59 am »
The attribute. How do i give the attribute a value. I defined the attribute with the block definition. I saw a way that defines the attribute with the blockreference but i couldn't use it.
« Last Edit: April 29, 2012, 05:00:36 am by poncelet »
Ce que femme veut, Dieu le veut.

kaefer

  • Swamp Rat
  • Posts: 538
Re: i ❤ attributes
« Reply #11 on: April 29, 2012, 05:08:20 am »
The attribute. How do i give the attribute a value.

The AttributeReference. You create a new one.

Code - F#: [Select]
  1. let ar = new AttributeReference()
  2. ar.SetAttributeFromBlock(ad, br.BlockTransform)
  3. ar.TextString <- someValue // here you go
  4. br.AttributeCollection.AppendAttribute ar |> ignore
  5. tr.AddNewlyCreatedDBObject(ar, true)

poncelet

  • Newt
  • Posts: 51
Re: i ❤ attributes
« Reply #12 on: April 29, 2012, 05:15:55 am »
The attribute. How do i give the attribute a value.

The AttributeReference. You create a new one.

Code - F#: [Select]
  1. let ar = new AttributeReference()
  2. ar.SetAttributeFromBlock(ad, br.BlockTransform)
  3. ar.TextString <- someValue // here you go
  4. br.AttributeCollection.AppendAttribute ar |> ignore
  5. tr.AddNewlyCreatedDBObject(ar, true)

ad is the attribute definition. I just need the object id of this when i append it?
Also the blockreference has to be commited before i add the attribute?
Ce que femme veut, Dieu le veut.

poncelet

  • Newt
  • Posts: 51
Re: i ❤ attributes
« Reply #13 on: April 29, 2012, 09:45:20 am »
Kaefer thanks! I had to separate the attribute definition inside the class but it worked.
*cheers*
Ce que femme veut, Dieu le veut.