We have get to put a block in a tool palette using the tips you have done.
The steps we have follow are:
1. Find the block and get de ObjectID
2. Select the block
3. Copy to clipboard
4. Find the tool palette by name
5. Paste the content of the clipboard.
We have had some problems using .NET SendStringToExecute and copy and paste commands needed to be execute sincronously, that is way whe hace user COM SendCommand instead.
To do the PASTE we have done an ObjectARX function, perhaps there is a easier way to do this.
Here you are the code, beginins one we have the Block Object ID.
Thanks
Maitere
Public Shared Sub AddBlockReferenceToPalette2 _
( _
ByVal nombrePaleta As String, _
ByVal brefObjectId As ObjectId, ByRef docBloque As Document _
)
'Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
'Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = docBloque.Editor
Dim doc As Document = docBloque
If Not brefObjectId.IsNull Then
' Se busca la paleta
Dim ps As System.IntPtr = AcTcUiGetToolPaletteWindow()
Dim pal As System.IntPtr = CAcTcUiToolPaletteSet_FindPalette(ps, nombrePaleta, System.IntPtr.Zero, False)
If pal <> System.IntPtr.Zero Then
ed.SetImpliedSelection(New ObjectId() {brefObjectId})
'Copiar bloque a portapapeles
'doc.SendStringToExecute("_copyclip ", True, False, True)
' MAITERE
' Se usa SendCommand de COM para que lo haga de forma inmediata, sino .NET lo hace de forma asincrona
Dim app As Autodesk.AutoCAD.Interop.AcadApplication = Application.AcadApplication
app.ActiveDocument.SendCommand("_copyclip ")
' Se copia el bloque a la paleta-> se llama a un comando de ARX
'doc.SendStringToExecute("PegarBloquePaleta " + nombrePaleta + Chr(13), True, False, False)
' MAITERE
' Se usa SendCommand de COM para que lo haga de forma inmediata, sino .NET lo hace de forma asincrona
app.ActiveDocument.SendCommand("PasteBloquePaleta " + nombrePaleta + Chr(13))
End If
End If
End Sub
' To paste de selection block we have put in the clipboard we have done a ObjectARX Function.
void PasteBloquePaleta()
{
TCHAR nombrePaleta[1000];
int res;
res = acedGetString (1, _T("\nPaleta de destino: "), nombrePaleta);
CAcTcUiToolPaletteSet* ps = AcTcUiGetToolPaletteWindow();
CAcTcUiToolPalette* pal = ps->FindPalette(nombrePaleta, NULL, FALSE);
if (pal == NULL)
return;
IDataObject* pdo;
if (SUCCEEDED(::OleGetClipboard(&pdo)))
{
if (pal->Paste(pdo, 0, NULL))
{
pal->S
// success
}
}
}