<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Does a block exist with Delphi in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/does-a-block-exist-with-delphi/m-p/348464#M77774</link>
    <description>I'm using Delphi to try and find if a block exists in a drawing.  The Logic&lt;BR /&gt;
should be the same as VBA however, I think I'm missing something really&lt;BR /&gt;
minor.  What type of argument do I supply for the ThisDrawing.Blocks(?)&lt;BR /&gt;
&lt;BR /&gt;
My code is:&lt;BR /&gt;
&lt;BR /&gt;
var&lt;BR /&gt;
   blockRefObj      : IAcadBlockReference;&lt;BR /&gt;
   sBlkName          : widestring;&lt;BR /&gt;
   sACADPath       : string;&lt;BR /&gt;
begin&lt;BR /&gt;
   sACADPath := dtmGAFloatingOptions.appAcadApp.Path;//Path to AutoCAD&lt;BR /&gt;
   sBlkName := sACADPath+'\PREVRDGS.dwg';//Name of block to insert.&lt;BR /&gt;
   if blockRefObj =&lt;BR /&gt;
dtmGAFloatingOptions.appAcadApp.ActiveDocument.Blocks(sBlkName) then&lt;BR /&gt;
      Showmessage ('Block exists');&lt;BR /&gt;
end;</description>
    <pubDate>Mon, 21 Jan 2002 09:01:24 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2002-01-21T09:01:24Z</dc:date>
    <item>
      <title>Does a block exist with Delphi</title>
      <link>https://forums.autodesk.com/t5/vba-forum/does-a-block-exist-with-delphi/m-p/348464#M77774</link>
      <description>I'm using Delphi to try and find if a block exists in a drawing.  The Logic&lt;BR /&gt;
should be the same as VBA however, I think I'm missing something really&lt;BR /&gt;
minor.  What type of argument do I supply for the ThisDrawing.Blocks(?)&lt;BR /&gt;
&lt;BR /&gt;
My code is:&lt;BR /&gt;
&lt;BR /&gt;
var&lt;BR /&gt;
   blockRefObj      : IAcadBlockReference;&lt;BR /&gt;
   sBlkName          : widestring;&lt;BR /&gt;
   sACADPath       : string;&lt;BR /&gt;
begin&lt;BR /&gt;
   sACADPath := dtmGAFloatingOptions.appAcadApp.Path;//Path to AutoCAD&lt;BR /&gt;
   sBlkName := sACADPath+'\PREVRDGS.dwg';//Name of block to insert.&lt;BR /&gt;
   if blockRefObj =&lt;BR /&gt;
dtmGAFloatingOptions.appAcadApp.ActiveDocument.Blocks(sBlkName) then&lt;BR /&gt;
      Showmessage ('Block exists');&lt;BR /&gt;
end;</description>
      <pubDate>Mon, 21 Jan 2002 09:01:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/does-a-block-exist-with-delphi/m-p/348464#M77774</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2002-01-21T09:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: Does a block exist with Delphi</title>
      <link>https://forums.autodesk.com/t5/vba-forum/does-a-block-exist-with-delphi/m-p/348465#M77775</link>
      <description>"Darrell" &lt;DPELLETIER&gt; wrote in message&lt;BR /&gt;
news:3C9C76F76CDEC8C4FEE2F6452A47FA24@in.WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; I'm using Delphi to try and find if a block exists in a drawing.  The&lt;BR /&gt;
Logic&lt;BR /&gt;
&amp;gt; should be the same as VBA however, I think I'm missing something really&lt;BR /&gt;
&amp;gt; minor.  What type of argument do I supply for the ThisDrawing.Blocks(?)&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; My code is:&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; var&lt;BR /&gt;
&amp;gt;    blockRefObj      : IAcadBlockReference;&lt;BR /&gt;
&amp;gt;    sBlkName          : widestring;&lt;BR /&gt;
&amp;gt;    sACADPath       : string;&lt;BR /&gt;
&amp;gt; begin&lt;BR /&gt;
&amp;gt;    sACADPath := dtmGAFloatingOptions.appAcadApp.Path;//Path to AutoCAD&lt;BR /&gt;
&amp;gt;    sBlkName := sACADPath+'\PREVRDGS.dwg';//Name of block to insert.&lt;BR /&gt;
&amp;gt;    if blockRefObj =&lt;BR /&gt;
&amp;gt; dtmGAFloatingOptions.appAcadApp.ActiveDocument.Blocks(sBlkName) then&lt;BR /&gt;
&amp;gt;       Showmessage ('Block exists');&lt;BR /&gt;
&amp;gt; end;&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&lt;BR /&gt;
In Delphi, you can't omit the name of the default property&lt;BR /&gt;
(usually 'Item()' for collections) unless you make a few&lt;BR /&gt;
changes to the type library import unit.&lt;BR /&gt;
&lt;BR /&gt;
So, where you use Document.Blocks(blockname) in VBA, you&lt;BR /&gt;
must use Document.Blocks.Item(Blockname) in Delphi.&lt;BR /&gt;
&lt;BR /&gt;
This function will return True if a block exists:&lt;BR /&gt;
&lt;BR /&gt;
Function BlockExists(Doc: AcadDocument; BlockName: String): Boolean&lt;BR /&gt;
begin&lt;BR /&gt;
  try&lt;BR /&gt;
    Doc.Blocks.Item(BlockName);&lt;BR /&gt;
    Result := True;&lt;BR /&gt;
  except&lt;BR /&gt;
    Result := False;&lt;BR /&gt;
  end;&lt;BR /&gt;
end;&lt;/DPELLETIER&gt;</description>
      <pubDate>Mon, 21 Jan 2002 13:20:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/does-a-block-exist-with-delphi/m-p/348465#M77775</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2002-01-21T13:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: Does a block exist with Delphi</title>
      <link>https://forums.autodesk.com/t5/vba-forum/does-a-block-exist-with-delphi/m-p/348466#M77776</link>
      <description>var&lt;BR /&gt;
&lt;BR /&gt;
blockRefObj : IACADBlockReference;&lt;BR /&gt;
&lt;BR /&gt;
Begin&lt;BR /&gt;
&lt;BR /&gt;
if BlockExists(currDwg, BlockName) then&lt;BR /&gt;
&lt;BR /&gt;
   blockRefObj := currDwg.Blocks.????&lt;BR /&gt;
&lt;BR /&gt;
End;&lt;BR /&gt;
&lt;BR /&gt;
"Darrell" &lt;DPELLETIER&gt; wrote in message&lt;BR /&gt;
news:3C9C76F76CDEC8C4FEE2F6452A47FA24@in.WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; I'm using Delphi to try and find if a block exists in a drawing.  The&lt;BR /&gt;
Logic&lt;BR /&gt;
&amp;gt; should be the same as VBA however, I think I'm missing something really&lt;BR /&gt;
&amp;gt; minor.  What type of argument do I supply for the ThisDrawing.Blocks(?)&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; My code is:&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; var&lt;BR /&gt;
&amp;gt;    blockRefObj      : IAcadBlockReference;&lt;BR /&gt;
&amp;gt;    sBlkName          : widestring;&lt;BR /&gt;
&amp;gt;    sACADPath       : string;&lt;BR /&gt;
&amp;gt; begin&lt;BR /&gt;
&amp;gt;    sACADPath := dtmGAFloatingOptions.appAcadApp.Path;//Path to AutoCAD&lt;BR /&gt;
&amp;gt;    sBlkName := sACADPath+'\PREVRDGS.dwg';//Name of block to insert.&lt;BR /&gt;
&amp;gt;    if blockRefObj =&lt;BR /&gt;
&amp;gt; dtmGAFloatingOptions.appAcadApp.ActiveDocument.Blocks(sBlkName) then&lt;BR /&gt;
&amp;gt;       Showmessage ('Block exists');&lt;BR /&gt;
&amp;gt; end;&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;/DPELLETIER&gt;</description>
      <pubDate>Mon, 21 Jan 2002 15:08:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/does-a-block-exist-with-delphi/m-p/348466#M77776</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2002-01-21T15:08:04Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/does-a-block-exist-with-delphi/m-p/348467#M77777</link>
      <description>You're confusing block references and blocks.&lt;BR /&gt;
&lt;BR /&gt;
Block references (AcadBlockReference) are created with&lt;BR /&gt;
the INSERT command.&lt;BR /&gt;
&lt;BR /&gt;
Blocks (AcadBlock) are created with the BLOCK command.&lt;BR /&gt;
&lt;BR /&gt;
What exactly are you trying to get (a block, or a&lt;BR /&gt;
block reference) ?&lt;BR /&gt;
&lt;BR /&gt;
"Darrell" &lt;DPELLETIER&gt; wrote in message&lt;BR /&gt;
news:582595DD221186AFEF3DF0AE377EF30A@in.WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; var&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; blockRefObj : IACADBlockReference;&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Begin&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; if BlockExists(currDwg, BlockName) then&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;    blockRefObj := currDwg.Blocks.????&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; End;&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; "Darrell" &lt;DPELLETIER&gt; wrote in message&lt;BR /&gt;
&amp;gt; news:3C9C76F76CDEC8C4FEE2F6452A47FA24@in.WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; &amp;gt; I'm using Delphi to try and find if a block exists in a drawing.  The&lt;BR /&gt;
&amp;gt; Logic&lt;BR /&gt;
&amp;gt; &amp;gt; should be the same as VBA however, I think I'm missing something really&lt;BR /&gt;
&amp;gt; &amp;gt; minor.  What type of argument do I supply for the ThisDrawing.Blocks(?)&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt; My code is:&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt; var&lt;BR /&gt;
&amp;gt; &amp;gt;    blockRefObj      : IAcadBlockReference;&lt;BR /&gt;
&amp;gt; &amp;gt;    sBlkName          : widestring;&lt;BR /&gt;
&amp;gt; &amp;gt;    sACADPath       : string;&lt;BR /&gt;
&amp;gt; &amp;gt; begin&lt;BR /&gt;
&amp;gt; &amp;gt;    sACADPath := dtmGAFloatingOptions.appAcadApp.Path;//Path to AutoCAD&lt;BR /&gt;
&amp;gt; &amp;gt;    sBlkName := sACADPath+'\PREVRDGS.dwg';//Name of block to insert.&lt;BR /&gt;
&amp;gt; &amp;gt;    if blockRefObj =&lt;BR /&gt;
&amp;gt; &amp;gt; dtmGAFloatingOptions.appAcadApp.ActiveDocument.Blocks(sBlkName) then&lt;BR /&gt;
&amp;gt; &amp;gt;       Showmessage ('Block exists');&lt;BR /&gt;
&amp;gt; &amp;gt; end;&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;/DPELLETIER&gt;&lt;/DPELLETIER&gt;</description>
      <pubDate>Mon, 21 Jan 2002 17:10:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/does-a-block-exist-with-delphi/m-p/348467#M77777</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2002-01-21T17:10:11Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/does-a-block-exist-with-delphi/m-p/348468#M77778</link>
      <description>I have a function that inserts a block into a drawing&lt;BR /&gt;
blockRefObj := currDwg.ModelSpace.InsertBlock(varInsPoint,&lt;BR /&gt;
sBlkName,sXScale,sXScale,sXScale,0.0);&lt;BR /&gt;
&lt;BR /&gt;
but first, I check too see if the block is already inserted in the drawing&lt;BR /&gt;
if BlockExists (currDwg,sBlkName)then&lt;BR /&gt;
&lt;BR /&gt;
If the block already exists then just modify the attributes, if not, then&lt;BR /&gt;
insert it and modify the attributes.&lt;BR /&gt;
&lt;BR /&gt;
"Tony Tanzillo" &lt;TONY.TANZILLO&gt; wrote in message&lt;BR /&gt;
news:DBDEF14F2818467C9C70D47B40F4A677@in.WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; You're confusing block references and blocks.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Block references (AcadBlockReference) are created with&lt;BR /&gt;
&amp;gt; the INSERT command.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Blocks (AcadBlock) are created with the BLOCK command.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; What exactly are you trying to get (a block, or a&lt;BR /&gt;
&amp;gt; block reference) ?&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; "Darrell" &lt;DPELLETIER&gt; wrote in message&lt;BR /&gt;
&amp;gt; news:582595DD221186AFEF3DF0AE377EF30A@in.WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; &amp;gt; var&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt; blockRefObj : IACADBlockReference;&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt; Begin&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt; if BlockExists(currDwg, BlockName) then&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;    blockRefObj := currDwg.Blocks.????&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt; End;&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt; "Darrell" &lt;DPELLETIER&gt; wrote in message&lt;BR /&gt;
&amp;gt; &amp;gt; news:3C9C76F76CDEC8C4FEE2F6452A47FA24@in.WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; &amp;gt; &amp;gt; I'm using Delphi to try and find if a block exists in a drawing.  The&lt;BR /&gt;
&amp;gt; &amp;gt; Logic&lt;BR /&gt;
&amp;gt; &amp;gt; &amp;gt; should be the same as VBA however, I think I'm missing something&lt;BR /&gt;
really&lt;BR /&gt;
&amp;gt; &amp;gt; &amp;gt; minor.  What type of argument do I supply for the&lt;BR /&gt;
ThisDrawing.Blocks(?)&lt;BR /&gt;
&amp;gt; &amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt; &amp;gt; My code is:&lt;BR /&gt;
&amp;gt; &amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt; &amp;gt; var&lt;BR /&gt;
&amp;gt; &amp;gt; &amp;gt;    blockRefObj      : IAcadBlockReference;&lt;BR /&gt;
&amp;gt; &amp;gt; &amp;gt;    sBlkName          : widestring;&lt;BR /&gt;
&amp;gt; &amp;gt; &amp;gt;    sACADPath       : string;&lt;BR /&gt;
&amp;gt; &amp;gt; &amp;gt; begin&lt;BR /&gt;
&amp;gt; &amp;gt; &amp;gt;    sACADPath := dtmGAFloatingOptions.appAcadApp.Path;//Path to AutoCAD&lt;BR /&gt;
&amp;gt; &amp;gt; &amp;gt;    sBlkName := sACADPath+'\PREVRDGS.dwg';//Name of block to insert.&lt;BR /&gt;
&amp;gt; &amp;gt; &amp;gt;    if blockRefObj =&lt;BR /&gt;
&amp;gt; &amp;gt; &amp;gt; dtmGAFloatingOptions.appAcadApp.ActiveDocument.Blocks(sBlkName) then&lt;BR /&gt;
&amp;gt; &amp;gt; &amp;gt;       Showmessage ('Block exists');&lt;BR /&gt;
&amp;gt; &amp;gt; &amp;gt; end;&lt;BR /&gt;
&amp;gt; &amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;/DPELLETIER&gt;&lt;/DPELLETIER&gt;&lt;/TONY.TANZILLO&gt;</description>
      <pubDate>Tue, 22 Jan 2002 07:13:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/does-a-block-exist-with-delphi/m-p/348468#M77778</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2002-01-22T07:13:54Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/does-a-block-exist-with-delphi/m-p/348469#M77779</link>
      <description>"Darrell" &lt;DPELLETIER&gt; wrote in message&lt;BR /&gt;
news:2D9F5B301FFE4FC629028F6D4EBE251D@in.WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; I have a function that inserts a block into a drawing&lt;BR /&gt;
&amp;gt; blockRefObj := currDwg.ModelSpace.InsertBlock(varInsPoint,&lt;BR /&gt;
&amp;gt; sBlkName,sXScale,sXScale,sXScale,0.0);&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; but first, I check too see if the block is already inserted in the drawing&lt;BR /&gt;
&amp;gt; if BlockExists (currDwg,sBlkName)then&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; If the block already exists then just modify the attributes, if not, then&lt;BR /&gt;
&amp;gt; insert it and modify the attributes.&lt;BR /&gt;
&lt;BR /&gt;
You're still confusing blocks and block references.&lt;BR /&gt;
&lt;BR /&gt;
The BlockExists() function tells you if the block&lt;BR /&gt;
exists, it does not tell you if one or more insertions&lt;BR /&gt;
of the block exists.&lt;BR /&gt;
&lt;BR /&gt;
It sounds like you need to locate the existing&lt;BR /&gt;
insertion of the block and if found, modify its&lt;BR /&gt;
attributes. Otherwise, you would insert it.&lt;BR /&gt;
&lt;BR /&gt;
To find the existing insertion, you will need to&lt;BR /&gt;
use a selection set filter that creates a selection&lt;BR /&gt;
set that contains all insertions of the block, and&lt;BR /&gt;
then what you do from there is up to you.&lt;BR /&gt;
&lt;BR /&gt;
var&lt;BR /&gt;
  ss: AcadSelectionSet;&lt;BR /&gt;
  BlockRef: AcadBlockReference;&lt;BR /&gt;
  Doc: AcadDocument;&lt;BR /&gt;
  vaType, vaData: OleVariant;&lt;BR /&gt;
begin&lt;BR /&gt;
  vaType := VarArrayCreate([0, 1], varSmallInt);&lt;BR /&gt;
  vaType[0] := 0; vaType[1] := 2;&lt;BR /&gt;
  vaData := ArrayOf(["INSERT", "MYBLOCKNAME"]);&lt;BR /&gt;
  Doc = &amp;lt;&lt;GET document="" object=""&gt;&amp;gt;&lt;BR /&gt;
  ss := Doc.PickFirstSelectionSet;&lt;BR /&gt;
  ss.Clear;&lt;BR /&gt;
  ss.Select(acSelectionSetAll, EmptyParam,&lt;BR /&gt;
             EmptyParam, vaType, vaData);&lt;BR /&gt;
  if ss.Count = 0 then&lt;BR /&gt;
    BlockRef := Doc.ModelSpace.InsertBlock(...)&lt;BR /&gt;
  else&lt;BR /&gt;
    BlockRef := ss.Item(0) As AcadBlockReference;&lt;BR /&gt;
&lt;BR /&gt;
// At this point, BlockRef is either the existing&lt;BR /&gt;
// insertion of the block or a new insertion of it&lt;BR /&gt;
// This of course assumes that there will be only&lt;BR /&gt;
// one insertion of the block in the drawing, but&lt;BR /&gt;
// if there are more than one, what you do about&lt;BR /&gt;
// that is up to you.&lt;BR /&gt;
&lt;BR /&gt;
end;&lt;/GET&gt;&lt;/DPELLETIER&gt;</description>
      <pubDate>Tue, 22 Jan 2002 08:16:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/does-a-block-exist-with-delphi/m-p/348469#M77779</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2002-01-22T08:16:25Z</dc:date>
    </item>
  </channel>
</rss>

