VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trying to read drawings without opening them.

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
148 Views, 8 Replies

Trying to read drawings without opening them.

I wrote a program in VBA (using some samples from Autodesk) that can retrieve certain information from drawings without opening them. It works beautifully in VBA, but since I can't pass a drawing name to VBA when calling it, I need to write it in plain ol' VB. When I do this, I get a nice error that reads as follows...

"The instruction at "0x654dd6bc" referenced memory at "0x00000000". The memory could not be "read". Click on OK to terminate the program."

This error occurs on this line of code...

Set mDoc = New AXDB15Lib.AxDbDocument.

I'm guessing that I need to establish some kind of connection to AutoCAD, I've tried some things, but still get this error. Anybody know anything?


Thanks

Todd

8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: Anonymous

nevermind. I got it figured out. Thanks

Todd
Message 3 of 9
Anonymous
in reply to: Anonymous

curious, what was the solution? change to Set mdoc =
GetInterfaceObject("ObjectDBX.AxDbDocument") ???

"treyball3" wrote in message
news:f174782.0@WebX.maYIadrTaRb...
nevermind. I got it figured out. Thanks
Todd
Message 4 of 9
Anonymous
in reply to: Anonymous

hey man,

    it's great u hv solved the
problem.

    however, i am also very much
interested in how to read block information from .dwg files without opening
AutoCad application.

    any chance to share how u hv
done?

    thanx.

 

rgds,

soe


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
nevermind.
I got it figured out. Thanks
Todd
Message 5 of 9
Anonymous
in reply to: Anonymous

I am also interested in access block information
using ObjectDBX but more specifically modifying a certain attribute
value.

I have managed to get the drawing/block information
but I am having trouble doing the final step ie updating the attribute. I'm
probably using the worng method/object

Any ideas would be appreciated

 

kip

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

hey man,

    it's great u hv solved the
problem.

    however, i am also very much
interested in how to read block information from .dwg files without opening
AutoCad application.

    any chance to share how u hv
done?

    thanx.

 

rgds,

soe


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
nevermind.
I got it figured out. Thanks
Todd
Message 6 of 9
Anonymous
in reply to: Anonymous

how d'u read the block attribute information, can u
share?

thanx.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

I am also interested in access block information
using ObjectDBX but more specifically modifying a certain attribute
value.

I have managed to get the drawing/block
information but I am having trouble doing the final step ie updating the
attribute. I'm probably using the worng method/object

Any ideas would be appreciated

 

kip

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

hey man,

    it's great u hv solved the
problem.

    however, i am also very much
interested in how to read block information from .dwg files without opening
AutoCad application.

    any chance to share how u hv
done?

    thanx.

 

rgds,

soe


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
nevermind.
I got it figured out. Thanks

Todd
Message 7 of 9
Anonymous
in reply to: Anonymous

i'm no expert but i think the general idea
is:

(just pseudocode, not exact syntax)

this assumes you mean you want attribs in block
references, not attdefs in block definitions...

 

make sure objectdbx is referenced

make sure objectdbx is registered

get objdbx object

open document with objdbx obj

get ms of doc eg

set ms = oDoc.ModelSpace

foreach obj in ms

    if type obj =
blockreference


size=2>          atts =
obj.GetAttributes

        foreach att
atts


size=2>           ...do
whatever

        next
att

next obj

etc


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

how d'u read the block attribute information, can
u share?

thanx.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

size=2>
 
Message 8 of 9
Anonymous
in reply to: Anonymous

any chance to have coding.

thanx.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

i'm no expert but i think the general idea
is:

(just pseudocode, not exact syntax)

this assumes you mean you want attribs in block
references, not attdefs in block definitions...

 

make sure objectdbx is referenced

make sure objectdbx is registered

get objdbx object

open document with objdbx obj

get ms of doc eg

set ms = oDoc.ModelSpace

foreach obj in ms

    if type obj =
blockreference


size=2>          atts =
obj.GetAttributes

        foreach att
atts


size=2>           ...do
whatever

        next
att

next obj

etc


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

how d'u read the block attribute information,
can u share?

thanx.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

size=2>
 
Message 9 of 9
Anonymous
in reply to: Anonymous

sorry, I don't have anything that works
yet

here is my first try but it doesn't work
yet

maybe you can get to work

i modified a sample from tony that did something
else, but don't have it working yet, apologies Tony...

i thought this would be the general idea of a way
to go but ???

 

'apologies to original author whose code
'I have
mangled below to try to show you a sample.
'original code
'From: Tony
Tanzillo (
href="mailto:tony.tanzillo@caddzone.com">tony.tanzillo@caddzone.com
)
'posted
to ng the other day
'Remember that you must check "ObjectDBX 1.0 Type
Library"
'from the Tools|References dialog.

 

Public Sub Test()
    Dim Dwg As
String
    Dwg = "C:\0\test\test.dwg"
   
Dim BlockName As String
    BlockName =
"Test2"
    Dim blkcol As Collection
   
blkcol = GetBlocks(Dwg, BlockName)
    Dim blkref As
AXDB15Lib.AcadBlockReference
    Dim i As
Integer
    For Each blkref In
blkcol
      If blkref.HasAttributes
Then
        For i = LBound(BlkAtts) To
UBound(BlkAtts)
        MsgBox
BlkAtts(i).TextString
        Next
i
      End If
    Next
blkref
     
End Sub

 

Public Function GetBlocks(DwgName As String,
_
                   
BlkName As String
_
                   
) As Collection
    On Error GoTo Failed
   
Dim DbxDoc As AxDbDocument
    Set DbxDoc =
GetInterfaceObject("ObjectDBX.AxDbDocument")
    DbxDoc.Open
DwgName
    Dim aobj As
AXDB15Lib.AcadObject
    Dim bObj As
AXDB15Lib.AcadBlockReference
    Dim blkcol As
Collection
   
    For Each aobj In
DbxDoc.ModelSpace
      MsgBox
TypeName(aobj)
     

      If TypeName(aobj) = "IAcadBlockReference"
Then
        Set bObj =
aobj
        If bObj.Name = BlkName
Then
         blkcol.Add
bObj
         End
If
        End If
   
Next aobj
  GetBlocks = blkcol
Failed:
End Function

 



style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
any chance to have coding.

thanx.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost