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

Why is the SET method gaving me errors?

3 REPLIES 3
Reply
Message 1 of 4
davidbell
336 Views, 3 Replies

Why is the SET method gaving me errors?

Below is the code for a sub that is being called from anouther one of my subroutines. If you need the rest I can post it but lets hope that will not be needed.

The error that I am getting is :
"calling method SetObjectId of Interface IAcadBaseObject failed"

Whats this mean and how do I look in the help sysstem for information as to how to correct these errors?

MY code:
'This could be modified to run as a stand alone if you need to test it!
Sub InsertMyBlock(blockName As String, insertPnt As Variant)
' This example creates a block containing a circle. It then inserts the block.
Dim filePath As String
filePath = "C:\Documents and Settings\Owner\Desktop\ACAD_STUFF\Blocks\"
' Create the block
Dim myBlockObj As AcadBlock
Dim myInsertionPnt(0 To 2) As Double
myInsertionPnt(0) = 0#
myInsertionPnt(1) = 0#
myInsertionPnt(2) = 0#
'myBlockObj = ThisDrawing.Blocks.Add(myInsertionPnt, filePath & blockName)
Set myBlockObj = ThisDrawing.Blocks.Add(myInsertionPnt, "C:\Documents and Settings\Owner\Desktop\ACAD_STUFF\Blocks\4x4.dwg")

' Insert the block
Dim blockRefObj As AcadBlockReference
myInsertionPnt(0) = insertPnt(0)
myInsertionPnt(1) = insertPnt(1)
myInsertionPnt(2) = 0
Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(myInsertionPnt, "myBlockObj", 1#, 1#, 1#, 0)

ZoomAll

End Sub
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: davidbell

Your problem is that the Block's name (Block name cannot contain "\", ":",
or should not be a full file name), or more precisely, your logic, is wrong.

What you are intent to do is to insert a block from file.
The logic should be: if the block already exists in drawing(Blocks
collection), you supply the block name ("4x4") to InsertBlock() method; if
the block does not exists in drawing, you can supply a full file name
("C:\...\4x4.dwg") to InsertBlock() method, after inserting, block
definition "4x4" is created in Blocks collection automatically.

In your logic, you created a BLANK block definition without AcadEntity in
the block. So, even if your "Set mBlockObj..." was OK, the code after that
only insered a blank block, which contains nothing.

So, you should remove the code that creates an AcadBlock object. Directly go
to ThisDrawing.ModelSpace.InsertBlock(insPoint, "C:\...\4x4.dwg",....).

But to make your code bullet-proof, you may want to do some verification
before inserting:

1. decide to use block name or full file name in "InserBlock()" method. You
can first to loop through AcadBlocks collection to see if the Block ("4x4")
definition exists or not. If yes, you use block name, if not, you use full
file name;
2. if you use full file name, you want to check if the *.dwg ("4x4.dwg")
file exists or not.

BTW, since you post in .NET NG, which implies you use VB.NET, can you still
use Variant type in VB.NET? Can you still use "Set ..."? Although have been
doing VB/VBA for long time, but in .NET, I use C#, never used VB.NET. But I
know Variant type is gone in VB.NET.


wrote in message news:4972903@discussion.autodesk.com...
Below is the code for a sub that is being called from anouther one of my
subroutines. If you need the rest I can post it but lets hope that will not
be needed.

The error that I am getting is :
"calling method SetObjectId of Interface IAcadBaseObject failed"

Whats this mean and how do I look in the help sysstem for information as to
how to correct these errors?

MY code:
'This could be modified to run as a stand alone if you need to test it!
Sub InsertMyBlock(blockName As String, insertPnt As Variant)
' This example creates a block containing a circle. It then inserts the
block.
Dim filePath As String
filePath = "C:\Documents and Settings\Owner\Desktop\ACAD_STUFF\Blocks\"
' Create the block
Dim myBlockObj As AcadBlock
Dim myInsertionPnt(0 To 2) As Double
myInsertionPnt(0) = 0#
myInsertionPnt(1) = 0#
myInsertionPnt(2) = 0#
'myBlockObj = ThisDrawing.Blocks.Add(myInsertionPnt, filePath &
blockName)
Set myBlockObj = ThisDrawing.Blocks.Add(myInsertionPnt, "C:\Documents
and Settings\Owner\Desktop\ACAD_STUFF\Blocks\4x4.dwg")

' Insert the block
Dim blockRefObj As AcadBlockReference
myInsertionPnt(0) = insertPnt(0)
myInsertionPnt(1) = insertPnt(1)
myInsertionPnt(2) = 0
Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(myInsertionPnt,
"myBlockObj", 1#, 1#, 1#, 0)

ZoomAll

End Sub
Message 3 of 4
davidbell
in reply to: davidbell

Thank you fr spending the time to answer my question. I am told that Variants dont work. I have not tried anything. I am just learning ang haven'tused it for autocad yet. I am not to sure about using SET in VB.NET. I do have it but I have not switch over quite yet. I am afraid of the problems I will have whilt trying to work between .net and acad / excel. I will be making the move sonner or later. One problem will be the variant variable. When I need to use the getpoint method in autocad, I will have anouther bump in the road.

I just looked in the help system and they do include the SET method/functin in VB.NET.
Message 4 of 4
Anonymous
in reply to: davidbell

You should be able to pass a variant to com by using an object. The marshaler should convert the object to a variant when passing it to com.

But why use com when the dotnet api can typically do it?
Example: Application.DocumentManager.MdiActiveDocument.Editor.GetPoint


Chris Arps Message was edited by: CArps

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