Author Topic: Using the Symbol Table & Syntax?  (Read 3079 times)

0 Members and 1 Guest are viewing this topic.

quamper

  • Guest
Using the Symbol Table & Syntax?
« on: January 08, 2007, 04:29:27 PM »
I've got some code that I want to use to for searching through blocks that uses the SymbolTable.. The code was from someone that helped me out on the Autodesk forums. It was in C# so I "translated it" into VB code. And I think I did a good job of converting it, but I'm slightly confused about the usage of one particular line and what I am supposed to pass to it.

The Arx documentation confuses the heck out of me sometimes. Most of the time I can figure it out but this one is stumping me. So if anyone can help or at least point me in the right direction

Code: [Select]
Dim table As SymbolTable = CType(trans.GetObject(TableId,OpenMode.ForRead), SymbolTable)
tableid is a variable that gets passed to the function, but I'm trying to figure out what that is supposed to be that I am passing to it? It tells me it needs to be DatabaseServices.ObjectID, but I can't figure out what I should passing? That's where I am stumped

The full function if anyone is curious is

Code: [Select]

Public Shared Function GetBlockName(ByVal tableId As ObjectId, ByVal prefix As String) As String
Dim names As ArrayList
Dim db As Database = HostApplicationServices.WorkingDatabase()
Using trans As Transaction = db.TransactionManager.StartTransaction()
Dim table As SymbolTable = CType(trans.GetObject(TableId,OpenMode.ForRead), SymbolTable)
Dim id As ObjectId

For Each id In table
If Not id.IsErased Then
Dim rec As SymbolTableRecord = CType(trans.GetObject(id,OpenMode.ForRead), SymbolTableRecord)
If rec.Name.StartsWith(prefix,StringComparison.InvariantCultureIgnoreCase) Then
names.Add(rec.Name)
End If
End If
Next

names.Sort()

Dim n As Integer =  0
While names.BinarySearch(String.Format("{0}{1}",prefix,n)) > -1
n = n + 1
End While
Return String.Format("{0}{1}", prefix, n)
End Using
End Function

Thanks! :)


Bobby C. Jones

  • Swamp Rat
  • Posts: 516
  • Cry havoc and let loose the dogs of war.
Re: Using the Symbol Table & Syntax?
« Reply #1 on: January 08, 2007, 04:44:01 PM »
This function is expecting an objectID of a block table.
Bobby C. Jones

LE

  • Guest
Re: Using the Symbol Table & Syntax?
« Reply #2 on: January 08, 2007, 04:46:08 PM »
Place the original one (C# version)...

I guess you need to change the transaction call to:

Code: [Select]
Using trans As Transaction = tableId.Database.TransactionManager.StartTransaction()

I by no means do anything in VB.NET by the way

Nathan Taylor

  • Guest
Re: Using the Symbol Table & Syntax?
« Reply #3 on: January 08, 2007, 04:53:55 PM »
The function is passed the ObjectId of your SymbolTable. That line is retrieving the SymbolTable from the passed ObjectID. So it is correct how it is.

On a side note as pointed out to me by Tony Tanzillo in the Autodesk Groups.

Quote
If i may suggest, try to avoid coupling your method to the
current working database or active document's database,
whenever the method takes a database-specific object as a
parameter.

IOW, use the Database property of the table ObjectId
passed as the first parameter instead of the current
working database.

Doing makes the method more generic and usable with
any database.

Change
Code: [Select]
Dim db As Database = HostApplicationServices.WorkingDatabase()To
Code: [Select]
Dim db As Database = tableId.Datbase
Regards - Nathan

LE

  • Guest
Re: Using the Symbol Table & Syntax?
« Reply #4 on: January 08, 2007, 05:01:54 PM »
Also, I think the call for the arraylist, is not properly done..., well the masters in VB.NET will correct that.

Code: [Select]
Dim names As ArrayList

To:

Code: [Select]
Dim names As New ArrayList()

quamper

  • Guest
Re: Using the Symbol Table & Syntax?
« Reply #5 on: January 08, 2007, 05:07:51 PM »
I guess I'm not asking my question correctly... I apologize for my naiveness :)

Quote
The function is passed the ObjectId of your SymbolTable. That line is retrieving the SymbolTable from the passed ObjectID.

For example below the snippet of my sub routine that calls the function... I'm wanting to create a block with the next available name in a sequence "Base1, Base2, Base3..."
Code: [Select]
Dim bt As BlockTable = trans.GetObject(db.BlockTableId,OpenMode.ForWrite)
Dim cabBtr As BlockTableRecord = New BlockTableRecord()
cabBtr.Name = modutilities.GetBlockName(tableid, "Base")

I realize that I need to pass the ObjectId of my symbol table, like you say, but what do I do to get that to pass it? If that makes sense?


quamper

  • Guest
Re: Using the Symbol Table & Syntax?
« Reply #6 on: January 08, 2007, 05:11:43 PM »
I guess I just answered my own question :) I spent all last week looking at this.. and I was horribly sick so I knew it wasn't the best time trying to figure it out.. :)

I should have been using db.BlockTableId I guess  :-D

Thanks for pointing out the error with my arraylist as well!