Author Topic: Total newby to the swamp... VB block insertion  (Read 34569 times)

0 Members and 1 Guest are viewing this topic.

Bob Wahr

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #45 on: May 23, 2006, 04:59:54 PM »
You will also want to familiarize yourself with Step Over (Shift+F8) and Step Out (Ctrl+Shift+F8) which will help you get through loops much less painlessly.  Another handy thing is setting breakpoints, which you do by clicking the bar on the left side of the code pane.  This puts a dot next to the line.  You can then run the program (F5) and it will stop when it comes to that line at which point you can start stepping through the code.  I use this a lot when I get to new bits of a routine, I know the first part is running as desired so I let it go and just start stepping at the part I am working on.

I would also advise you to keep your locals window open.  It takes up real estate but is a good way to check values while you are stepping through the code.

Bob Wahr

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #46 on: May 23, 2006, 05:01:39 PM »
Good to be back at least part time Jeff.  It's been a pretty rough year but hopefully is at least levelling out.

akdrafter

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #47 on: May 23, 2006, 05:07:15 PM »
My blkref is coming up empty.

-2145386445Filer error

My apologies for being a pain.

Bob Wahr

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #48 on: May 23, 2006, 05:09:46 PM »
no problem at all, ACAD's not finding the block.  Try this
Code: [Select]
    If ThisDrawing.ActiveSpace = acModelSpace Then
    inspnt = ThisDrawing.Utility.GetPoint(, vbCrLf & "Pick Insertion Point: ")
    Set blkref = ThisDrawing.ModelSpace.InsertBlock(inspnt, MyPath & blkName & ".dwg", 1, 1, 1, 0)
    End If
    If ThisDrawing.ActiveSpace = acPaperSpace Then
    inspnt = ThisDrawing.Utility.GetPoint(, vbCrLf & "Pick Insertion Point: ")
    Set blkref = ThisDrawing.PaperSpace.InsertBlock(inspnt, MyPath & blkName & ".dwg", 1, 1, 1, 0)
    End If

Bob Wahr

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #49 on: May 23, 2006, 05:13:31 PM »
For that matter, if active space is NOT ModelSpace, then it IS PaperSpace, there's no middle ground so instead of two If statements, you can combine them into one so you can go with
Code: [Select]
    inspnt = ThisDrawing.Utility.GetPoint(, vbCrLf & "Pick Insertion Point: ")
    If ThisDrawing.ActiveSpace = acModelSpace Then
      Set blkref = ThisDrawing.ModelSpace.InsertBlock(inspnt, MyPath & blkName & ".dwg", 1, 1, 1, 0)
    Else
      Set blkref = ThisDrawing.PaperSpace.InsertBlock(inspnt, MyPath & blkName & ".dwg", 1, 1, 1, 0)
    End If
Which is easier to follow for me at least.  If it's easier for you to keep track of it as two separate If statements, it's really not going to be too much of a drag so I would say go with what you can follow easiest (at least for now).

Bob Wahr

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #50 on: May 23, 2006, 05:17:58 PM »
to add that togather with Jeff's layer suggestion on the layering
Code: [Select]
    inspnt = ThisDrawing.Utility.GetPoint(, vbCrLf & "Pick Insertion Point: ")
    If ThisDrawing.ActiveSpace = acModelSpace Then
      Set blkref = ThisDrawing.ModelSpace.InsertBlock(inspnt, MyPath & blkName & ".dwg", 1, 1, 1, 0)
    Else
      Set blkref = ThisDrawing.PaperSpace.InsertBlock(inspnt, MyPath & blkName & ".dwg", 1, 1, 1, 0)
    End If
    blkref.Layer = blkLayer

akdrafter

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #51 on: May 23, 2006, 05:19:40 PM »
I figured there was a pathing issue. But, I was also wondering if I had the "Support File Search Path" set in my preferences.... would the app find the block if it was in one of those paths?

Could I create a variable that contained the blkName & ".dwg" extension so that I would have to have that in the InsertBlock. I would have figured that it would know it is to be a .dwg

Jeff_M

  • King Gator
  • Posts: 4048
  • C3D user & customizer
Re: Total newby to the swamp... VB block insertion
« Reply #52 on: May 23, 2006, 05:25:56 PM »
For that matter, if active space is NOT ModelSpace, then it IS PaperSpace...
While technically true, and I was going to advise Tim on this once he got everything thing else working, if the user is in ModelSPace inside of a PaperSpaceViewport Active space returns Paperspace, which is not where you want the block to be placed.....

Which is why I use:
Code: [Select]
Dim Space as AcadBlock
If ThisDrawing.GetVariable("CVPORT") = 1 Then
   Set Space = ThisDrawing.PaperSpace
Else
   Set Space = ThisDrawing.ModelSpace
End If

Set blkins = Space.InsertBlock.........
Which insures I will always work in the space that the user is working in.

akdrafter

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #53 on: May 23, 2006, 05:28:23 PM »
Yes... CVPORT

I was reading up on that in another thread. Was going to cross that bridge soon. :-)

Jeff_M

  • King Gator
  • Posts: 4048
  • C3D user & customizer
Re: Total newby to the swamp... VB block insertion
« Reply #54 on: May 23, 2006, 05:28:53 PM »
.... would the app find the block if it was in one of those paths? No

Could I create a variable that contained the blkName & ".dwg" extension so that I would have to have that in the InsertBlock. I would have figured that it would know it is to be a .dwg
Yes, and I'd go further and say that you should check if it is already in the drawing and only add the path & ".dwg" if it isn't, otherwise it will be read from disk everytime.....

Bob Wahr

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #55 on: May 23, 2006, 05:31:07 PM »
you can, when you get to insertion time change blkname by doing a

blkname = mypath & blkname & ".dwg"

then for the insertion, you can just use blkname, you could also add a new variable called insname or whatever else you want.

It doesn't know that it's a drawing because the InsertBlock method, inserts a block that is defined in the drawing, if there's not a block already defined in the drawing, you need to get explicit.  

*Good point Jeff, I was trying to simplify the statement and hadn't considered that.

**grr you guys are both typing faster than me, not fair.  Jeff, I was leaving the check for definition bit for later.

Jeff_M

  • King Gator
  • Posts: 4048
  • C3D user & customizer
Re: Total newby to the swamp... VB block insertion
« Reply #56 on: May 23, 2006, 05:38:33 PM »
**grr you guys are both typing faster than me, not fair.  Jeff, I was leaving the check for definition bit for later.
Heh, that's the first time I've ever been accused of *THAT* :lmao: I'm leaving for a bit anyway......I'll butt out for a while. ;-)

akdrafter

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #57 on: May 23, 2006, 06:16:04 PM »
Just when I thought it was working I am getting the following error....and the layer is not being created nor is the block being inserted on that layer.

-2145386476Key not found

Code: [Select]
Sub InsertButton_Click()
Dim inspnt As Variant
Dim blkref As AcadBlockReference
Dim layer As AcadLayer
'''
'''
    On Error Resume Next
    Set layer = ThisDrawing.Layers.Item(blkLayer)
    If Err.Number <> 0 Then
        Err.Clear
        Set layer = ThisDrawing.Layers.Item(blkLayer)
        layer.color = blkColor
        layer.Linetype = blkLType
    End If
   
    On Error GoTo err_han
    '''you should have something here to verify the block can be loaded.
    Me.hide
    inspnt = ThisDrawing.Utility.GetPoint(, vbCrLf & "Pick Insertion Point: ")
    If ThisDrawing.ActiveSpace = acModelSpace Then
      Set blkref = ThisDrawing.ModelSpace.InsertBlock(inspnt, MyPath & blkName & ".dwg", 1, 1, 1, 0)
      blkref.layer = blkLayer
    Else
      Set blkref = ThisDrawing.PaperSpace.InsertBlock(inspnt, MyPath & blkName & ".dwg", 1, 1, 1, 0)
      blkref.layer = blkLayer
    End If
ThisDrawing.Application.Update
Unload Me

Exit Sub

err_han:
Debug.Print Err.Number & Err.Description
   Exit Sub
End Sub

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
Re: Total newby to the swamp... VB block insertion
« Reply #58 on: May 23, 2006, 06:23:45 PM »
W/O scrolling up to your other code, did you ever use the ADD method to create it if it didn't exist?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

Bob Wahr

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #59 on: May 23, 2006, 06:28:41 PM »
Never Dim something with the same name as a property, method, etc.
Code: [Select]
Sub InsertButton_Click()
Dim inspnt As Variant
Dim blkref As AcadBlockReference
Dim objLayer As AcadLayer
'''
'''
    On Error Resume Next
    Set objlayer = ThisDrawing.Layers.Item(blkLayer)
    If Err.Number <> 0 Then
        Err.Clear
        Set objlayer = ThisDrawing.Layers.Item(blkLayer)
        objlayer.color = blkColor
        objlayer.Linetype = blkLType
    End If
   
    On Error GoTo err_han
    '''you should have something here to verify the block can be loaded.
    Me.hide
    inspnt = ThisDrawing.Utility.GetPoint(, vbCrLf & "Pick Insertion Point: ")
    If ThisDrawing.ActiveSpace = acModelSpace Then
      Set blkref = ThisDrawing.ModelSpace.InsertBlock(inspnt, MyPath & blkName & ".dwg", 1, 1, 1, 0)
      blkref.layer = blkLayer
    Else
      Set blkref = ThisDrawing.PaperSpace.InsertBlock(inspnt, MyPath & blkName & ".dwg", 1, 1, 1, 0)
      blkref.layer = blkLayer
    End If
ThisDrawing.Application.Update
Unload Me

Exit Sub

err_han:
Debug.Print Err.Number & Err.Description
   Exit Sub
End Sub