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

Is this a legitimate way to get an objectId from a handle string?

2 REPLIES 2
Reply
Message 1 of 3
tumpliner
347 Views, 2 Replies

Is this a legitimate way to get an objectId from a handle string?

{code}
static public bool getObjectId(string handle, out ObjectId gotId)
{

bool fRet = false;
Database db = HostApplicationServices.WorkingDatabase;

long gotHandleInt;
bool fHandleOK = NumbersClass.convertFromHex(handle, out gotHandleInt);
Int64 handleInt = Convert.ToInt64(gotHandleInt);
gotId = db.GetObjectId(false, new Handle(gotHandleInt),db.Indexctl);
if (gotId != ObjectId.Null)
{
fRet = true;
}
return fRet;
}

}
{code}

The convertFromHex is just a straightforward conversion from a hex string to an integer. It is odd that there does not seem to
be an Autodesk method that does this conversion of a handle to an objectId. It seems like something that would be very common to do,
yet I could not find any such method. So is this legitimate and/or is there a better way to do it?

Thanks, tumpliner
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: tumpliner

Well that's one way.

Here's another:

public class DatabaseExtensionMethods
{
public static ObjectId TryGetObjectId( this Database db, string handle )
{
if( string.IsNullOrEmpty( handle ) )
throw new ArgumentException( "Requires a valid object handle" );
long l = 0L;
if( !Int64.TryParse( handle, NumberStyles.AllowHexSpecifier, null, out
l ) )
return ObjectId.Null;
else
return db.GetObjectId( false, new Handle( l ), 0 );
}
}



--
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:6256785@discussion.autodesk.com...
{code}
static public bool getObjectId(string handle, out ObjectId gotId)
{

bool fRet = false;
Database db = HostApplicationServices.WorkingDatabase;

long gotHandleInt;
bool fHandleOK = NumbersClass.convertFromHex(handle, out
gotHandleInt);
Int64 handleInt = Convert.ToInt64(gotHandleInt);
gotId = db.GetObjectId(false, new
Handle(gotHandleInt),db.Indexctl);
if (gotId != ObjectId.Null)
{
fRet = true;
}
return fRet;
}

}
{code}

The convertFromHex is just a straightforward conversion from a hex string to
an integer. It is odd that there does not seem to
be an Autodesk method that does this conversion of a handle to an objectId.
It seems like something that would be very common to do,
yet I could not find any such method. So is this legitimate and/or is there
a better way to do it?

Thanks, tumpliner
Message 3 of 3
arcticad
in reply to: tumpliner

db.GetObjectId( false, new Handle( l ), 0 );

When I try to Convert this to VB,

db.GetObjectId(False, New Handle(l), 0)

I get an error.

Too many arguments to 'Public Sub New()'

for l

new handle() doesn't seem to have any parameters

What am I doing wrong?

Thanks
---------------------------



(defun botsbuildbots() (botsbuildbots))

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