Author Topic: Having trouble importing a block using command line  (Read 5644 times)

0 Members and 1 Guest are viewing this topic.

bharless72

  • Mosquito
  • Posts: 3
Having trouble importing a block using command line
« on: July 15, 2023, 02:29:56 PM »
Code - vb.net: [Select]
  1. Private Sub CommandButton1_Click()
  2.     frmBPDETGen.Hide
  3.    
  4.     ThisDrawing.SendCommand "_Canc" & vbCrLf
  5.    
  6.     ThisDrawing.SendCommand "-i" & vbCrLf
  7.     Wait 1
  8.     ThisDrawing.SendCommand "vvvv" & vbCrLf
  9.     Wait 1
  10.     ThisDrawing.SendCommand "1" & vbCrLf
  11.     Wait 1
  12.     ThisDrawing.SendCommand "1" & vbCrLf
  13.     Wait 1
  14.     ThisDrawing.SendCommand "1" & vbCrLf
  15.     Wait 1
  16.     ThisDrawing.SendCommand "0" & vbCrLf
  17. End Sub
  18.  
  19. Sub Wait(Seconds As Single)
  20.     Dim Start As Single
  21.     Start = Timer
  22.     Do While Timer < Start + Seconds
  23.         DoEvents
  24.     Loop
  25. End Sub
  26.  

It seems like after the block is imported the commands after are completely ignored. Any help is appreciated .


EDIT (John): Added code tags.
« Last Edit: July 18, 2023, 11:10:08 AM by JohnK »

57gmc

  • Bull Frog
  • Posts: 358
Re: Having trouble importing a block using command line
« Reply #1 on: July 17, 2023, 04:32:15 PM »
The SendCommand method is asynchronous. It runs after you vba code finishes. You need to use the vba api to import a block and insert it. For example, below is how I insert a titleblock at 0,0 where strFileName is the path to the block.

Code - Visual Basic: [Select]
  1. 'InsertTB:
  2.    Dim dInsert(0 To 2) As Double
  3.     dInsert(0) = 0#: dInsert(1) = 0#: dInsert(2) = 0#
  4.     Set oTbNew = ThisDrawing.PaperSpace.InsertBlock(dInsert, strDest & strFileName, 1, 1, 1, 0)
  5.     'put tb on specific layer
  6.    Set oNewLay = ThisDrawing.Layers.Add("TITLEBLK")
  7.     oTbNew.Layer = oNewLay.Name
« Last Edit: July 17, 2023, 04:38:40 PM by 57gmc »