<?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 Re: Select block reference by attribute value in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/select-block-reference-by-attribute-value/m-p/3717278#M52222</link>
    <description>&lt;P&gt;Hi Maitere,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code to copy an entity (specified by ObjectId) to the clipboard. I don't know how to paste it to a given tool palette yet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public static void CopyEntityToClipboard(ObjectId objectId)
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Editor editor = doc.Editor;
    using (doc.LockDocument())
    {
        editor.SetImpliedSelection(new ObjectId[] { objectId });
        doc.SendStringToExecute("_copyclip ", true, false, true);
    }
}

// Testing method&lt;BR /&gt;[CommandMethod("CopyEntityToClipboard")]
public static void CopyEntityToClipboard()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Editor editor = doc.Editor;
    PromptEntityResult entityResult = editor.GetEntity("Select an entity:");
    if (entityResult.Status == PromptStatus.OK)
    {
        CopyEntityToClipboard(entityResult.ObjectId);
    }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We can also use ToolPaletteManager and CustomToolBase classes to create a new palette, then add custom commands to this palette. Lookup Kean's &lt;A href="http://through-the-interface.typepad.com/through_the_interface/2009/10/streamlined-quicksaveas-command-for-autocad-2010.html" target="_self"&gt;code&lt;/A&gt; to see how to do it. But adding a block to the palette using API requires lots of work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Khoa&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 30 Nov 2012 06:49:19 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2012-11-30T06:49:19Z</dc:date>
    <item>
      <title>Select block reference by attribute value</title>
      <link>https://forums.autodesk.com/t5/net-forum/select-block-reference-by-attribute-value/m-p/3716512#M52219</link>
      <description>&lt;P&gt;I have a drawing with many block references on it and they have some attributes.&lt;/P&gt;&lt;P&gt;I know how to find the block reference witch the attribute value, and even change it but I don't know how to select it once I have the object ID of the block.&lt;/P&gt;&lt;P&gt;How can I do the selection without asking the user to select it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2012 18:43:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/select-block-reference-by-attribute-value/m-p/3716512#M52219</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-11-29T18:43:40Z</dc:date>
    </item>
    <item>
      <title>Re: Select block reference by attribute value</title>
      <link>https://forums.autodesk.com/t5/net-forum/select-block-reference-by-attribute-value/m-p/3716600#M52220</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once you have the ObjectId of an entity (block, line, circle...), use Editor.&lt;STRONG&gt;SetImpliedSelection&lt;/STRONG&gt;() method to &lt;U&gt;select this entity on the screen&lt;/U&gt; (the entity will be &lt;U&gt;highlighted with grips&lt;/U&gt;) without asking the user to manually select it. The following code snippet will help:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Application.DocumentManager.MdiActiveDocument.Editor.SetImpliedSelection(new ObjectId[] { entity.ObjectId });&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Khoa&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2012 19:33:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/select-block-reference-by-attribute-value/m-p/3716600#M52220</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-11-29T19:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: Select block reference by attribute value</title>
      <link>https://forums.autodesk.com/t5/net-forum/select-block-reference-by-attribute-value/m-p/3716620#M52221</link>
      <description>&lt;P&gt;Thanks for your soon answer. I will try tomorrow.&lt;/P&gt;&lt;P&gt;One more question.&lt;/P&gt;&lt;P&gt;How can I punt this selected object in the clipboard?&lt;/P&gt;&lt;P&gt;What I really want to do is to copy it and then "paste" in my tool palette.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Maitere&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2012 19:33:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/select-block-reference-by-attribute-value/m-p/3716620#M52221</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-11-29T19:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: Select block reference by attribute value</title>
      <link>https://forums.autodesk.com/t5/net-forum/select-block-reference-by-attribute-value/m-p/3717278#M52222</link>
      <description>&lt;P&gt;Hi Maitere,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code to copy an entity (specified by ObjectId) to the clipboard. I don't know how to paste it to a given tool palette yet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public static void CopyEntityToClipboard(ObjectId objectId)
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Editor editor = doc.Editor;
    using (doc.LockDocument())
    {
        editor.SetImpliedSelection(new ObjectId[] { objectId });
        doc.SendStringToExecute("_copyclip ", true, false, true);
    }
}

// Testing method&lt;BR /&gt;[CommandMethod("CopyEntityToClipboard")]
public static void CopyEntityToClipboard()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Editor editor = doc.Editor;
    PromptEntityResult entityResult = editor.GetEntity("Select an entity:");
    if (entityResult.Status == PromptStatus.OK)
    {
        CopyEntityToClipboard(entityResult.ObjectId);
    }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We can also use ToolPaletteManager and CustomToolBase classes to create a new palette, then add custom commands to this palette. Lookup Kean's &lt;A href="http://through-the-interface.typepad.com/through_the_interface/2009/10/streamlined-quicksaveas-command-for-autocad-2010.html" target="_self"&gt;code&lt;/A&gt; to see how to do it. But adding a block to the palette using API requires lots of work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Khoa&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2012 06:49:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/select-block-reference-by-attribute-value/m-p/3717278#M52222</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-11-30T06:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: Select block reference by attribute value</title>
      <link>https://forums.autodesk.com/t5/net-forum/select-block-reference-by-attribute-value/m-p/3718812#M52223</link>
      <description>&lt;P&gt;We have get to put a block in a tool palette using the tips you have done.&lt;/P&gt;&lt;P&gt;The steps we have follow are:&lt;/P&gt;&lt;P&gt;1. Find the block and get de ObjectID&lt;/P&gt;&lt;P&gt;2. Select the block&lt;/P&gt;&lt;P&gt;3. Copy to clipboard&lt;/P&gt;&lt;P&gt;4. Find the tool palette by name&lt;/P&gt;&lt;P&gt;5. Paste the content of the clipboard.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We have had some problems using .NET &amp;nbsp;SendStringToExecute and copy and paste commands needed to be execute sincronously, that is way whe hace user COM SendCommand instead.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To do the PASTE we have done an ObjectARX function, perhaps there is a easier way to do this.&lt;/P&gt;&lt;P&gt;Here you are the code, beginins one we have the Block Object ID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Maitere&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Public Shared Sub AddBlockReferenceToPalette2 _&lt;BR /&gt;( _&lt;BR /&gt;ByVal nombrePaleta As String, _&lt;BR /&gt;ByVal brefObjectId As ObjectId, ByRef docBloque As Document _&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;'Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor&lt;BR /&gt;'Dim doc As Document = Application.DocumentManager.MdiActiveDocument&lt;/P&gt;&lt;P&gt;Dim ed As Editor = docBloque.Editor&lt;BR /&gt;Dim doc As Document = docBloque&lt;/P&gt;&lt;P&gt;If Not brefObjectId.IsNull Then&lt;/P&gt;&lt;P&gt;' Se busca la paleta&lt;BR /&gt;Dim ps As System.IntPtr = AcTcUiGetToolPaletteWindow()&lt;BR /&gt;Dim pal As System.IntPtr = CAcTcUiToolPaletteSet_FindPalette(ps, nombrePaleta, System.IntPtr.Zero, False)&lt;BR /&gt;If pal &amp;lt;&amp;gt; System.IntPtr.Zero Then&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;ed.SetImpliedSelection(New ObjectId() {brefObjectId})&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;'Copiar bloque a portapapeles&lt;BR /&gt;'doc.SendStringToExecute("_copyclip ", True, False, True)&lt;BR /&gt;' MAITERE&lt;BR /&gt;' Se usa SendCommand de COM para que lo haga de forma inmediata, sino .NET lo hace de forma asincrona&lt;BR /&gt;Dim app As Autodesk.AutoCAD.Interop.AcadApplication = Application.AcadApplication&lt;BR /&gt;app.ActiveDocument.SendCommand("_copyclip ")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;' Se copia el bloque a la paleta-&amp;gt; se llama a un comando de ARX&lt;BR /&gt;'doc.SendStringToExecute("PegarBloquePaleta " + nombrePaleta + Chr(13), True, False, False)&lt;BR /&gt;' MAITERE&lt;BR /&gt;' Se usa SendCommand de COM para que lo haga de forma inmediata, sino .NET lo hace de forma asincrona&lt;BR /&gt;app.ActiveDocument.SendCommand("PasteBloquePaleta " + nombrePaleta + Chr(13))&lt;/P&gt;&lt;P&gt;End If&lt;BR /&gt;End If&lt;BR /&gt;End Sub&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;' To paste de selection block we have put in the clipboard we have done a ObjectARX Function.&lt;/P&gt;&lt;P&gt;void PasteBloquePaleta()&lt;BR /&gt;{&lt;BR /&gt;TCHAR nombrePaleta[1000];&lt;BR /&gt;int res;&lt;/P&gt;&lt;P&gt;res = acedGetString (1, _T("\nPaleta de destino: "), nombrePaleta);&lt;BR /&gt;&lt;BR /&gt;CAcTcUiToolPaletteSet* ps = AcTcUiGetToolPaletteWindow();&lt;BR /&gt;CAcTcUiToolPalette* pal = ps-&amp;gt;FindPalette(nombrePaleta, NULL, FALSE);&lt;BR /&gt;if (pal == NULL)&lt;BR /&gt;return;&lt;BR /&gt;&lt;BR /&gt;IDataObject* pdo;&lt;BR /&gt;if (SUCCEEDED(::OleGetClipboard(&amp;amp;pdo)))&lt;BR /&gt;{&lt;BR /&gt;if (pal-&amp;gt;Paste(pdo, 0, NULL))&lt;BR /&gt;{&lt;BR /&gt;pal-&amp;gt;S&lt;BR /&gt;// success&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Dec 2012 10:31:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/select-block-reference-by-attribute-value/m-p/3718812#M52223</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-12-01T10:31:12Z</dc:date>
    </item>
    <item>
      <title>Re: Select block reference by attribute value</title>
      <link>https://forums.autodesk.com/t5/net-forum/select-block-reference-by-attribute-value/m-p/3718990#M52224</link>
      <description>&lt;P&gt;It's very interesting that you can make it work with the combination of .NET, COM and ObjectARX. I hope you may see the &lt;A target="_self" href="http://adndevblog.typepad.com/autocad/2012/05/add-block-reference-to-a-tool-palette.html"&gt;blog&lt;/A&gt; from Adam Nagy. He presents the code to add a block reference to a specified tool palette using either ObjectARX or .NET with imported P/Invoke methods from AcTcUi.dll&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Khoa&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Dec 2012 18:46:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/select-block-reference-by-attribute-value/m-p/3718990#M52224</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-12-01T18:46:56Z</dc:date>
    </item>
    <item>
      <title>Re: Select block reference by attribute value</title>
      <link>https://forums.autodesk.com/t5/net-forum/select-block-reference-by-attribute-value/m-p/3719160#M52225</link>
      <description>&lt;P&gt;Yes, we have used the information of the article "Add block reference to a tool palette".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 02 Dec 2012 10:28:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/select-block-reference-by-attribute-value/m-p/3719160#M52225</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-12-02T10:28:20Z</dc:date>
    </item>
  </channel>
</rss>

