Author Topic: Rename Block on Insert?????  (Read 5936 times)

0 Members and 1 Guest are viewing this topic.

ML

  • Guest
I beg to differ
« Reply #15 on: March 16, 2005, 02:03:48 PM »
Jeff


Check this bit of code out
I wanted to thank Daron for the rename suggestion

Thanks Daron!


'Rename Block References

Code: [Select]

 For Each BlkRef In ThisDrawing.ModelSpace
   Select Case BlkRef.Name
    Case Is = "LEGEND KIT-Test"
     ThisDrawing.SendCommand "-rename" & vbCr & "Block" & vbCr & _
     "LEGEND KIT-Test" & vbCr & "LEGEND KIT-Test-1" & vbCr
    Case Is = "LEGEND KIT-Test-1"
     ThisDrawing.SendCommand "-rename" & vbCr & "Block" & vbCr & _
     "LEGEND KIT-Test-1" & vbCr & "LEGEND KIT-Test-2" & vbCr
    Case Is = "LEGEND KIT-Test-2"
     ThisDrawing.SendCommand "-rename" & vbCr & "Block" & vbCr & _
     "LEGEND KIT-Test-2" & vbCr & "LEGEND KIT-Test-3" & vbCr
    Case Is = "LEGEND KIT-Test-3"
     ThisDrawing.SendCommand "-rename" & vbCr & "Block" & vbCr & _
     "LEGEND KIT-Test-3" & vbCr & "LEGEND KIT-Test-4" & vbCr
    Case Is = "LEGEND KIT-Test-4"
     ThisDrawing.SendCommand "-rename" & vbCr & "Block" & vbCr & _
     "LEGEND KIT-Test-4" & vbCr & "LEGEND KIT-Test-5" & vbCr
    Case Is = "LEGEND KIT-Test-5"
     ThisDrawing.SendCommand "-rename" & vbCr & "Block" & vbCr & _
     "LEGEND KIT-Test-5" & vbCr & "LEGEND KIT-Test-6" & vbCr
   End Select


Jeff,

This part goes first and it now works like a charm

If BlockrefA is in drawing, rename to BlockrefB, If BlockrefB, rename to BlockrefC and so
By renaming the blocks first, there is no conflict between blockreference names and all seems to be working fine.

There is still one thing though:

If I explode a blockreference, then insert another one, the macro will then fail.

Any ideas?

Thanks again

Mark

Jeff_M

  • King Gator
  • Posts: 3946
  • C3D user & customizer
Rename Block on Insert?????
« Reply #16 on: March 16, 2005, 02:58:00 PM »
Mark,
I fail to see how this helps you.....just because you rename it does not change the block.... The name of the block is the same as the block definition. A block reference cannot have a different name than the block definition...

Did you think about the solution I mentioned? I mean the "save multiple Wblocks of the same block with the desired layers for the different scales....that, to me, is by far your best scenario.

IOW, take your base block; change the layers to match what they'd be for a 48 scale insert; SaveAs BA-SYMB-48; now change the layers to -96 and SaveAs BA-SYMB-96 and so on. Then have your code insert the proper block based on the scale.....then change the layer of the insert to the matching scale layer.....too easy, no having to rename blocks and layers, or check if the layers exist....the only thing I'd check for is if the block is already in the drawing, if it is just insert it, if not then grab the one on disk. This should also fix your exploding problem, too.

ML

  • Guest
Rename Block on Insert?????
« Reply #17 on: March 16, 2005, 03:19:19 PM »
Hey Jeff,

Of course I had thought about that but the person running the show here does not want multiple blocks of the same type on the server and I really don't blame him.

I am surprised that you don't see how renaming the blockreference after inserted has helped?

I wonder if you are still misunderstanding me but it is working very well.

Mark

ML

  • Guest
Rename Block on Insert?????
« Reply #18 on: March 16, 2005, 03:51:29 PM »
Ithink but I could be wrong, that the main problem was that there were duplicate blockreferences.

Now that each one has a unique name, it seems to be fine.

When I look at it, it does seems logical that I would have to do this but it is working.

THe problem may alos be that I am not setting a reference to the block reference.

Mark

Jeff_M

  • King Gator
  • Posts: 3946
  • C3D user & customizer
Rename Block on Insert?????
« Reply #19 on: March 16, 2005, 04:32:04 PM »
Quote from: ML
Ithink but I could be wrong, that the main problem was that there were duplicate blockreferences.

Now that each one has a unique name, it seems to be fine.

Mark

 :shock: Ding*Ding*Ding We have a winner!  :D
Mark, this is what I've been saying all along......except now you've gone further than need be.
And I just went back and saw the post that showed how you are inserting the block(s)......I'd forgotten that you were doing it via a menu macro.

I'll be right back with my recommendation for a working version for you......One quick question, though. The menu macro calls for a block INTERCONN1, or whatever, does it get inserted from a file if it's not in the drawing?

Jeff_M

  • King Gator
  • Posts: 3946
  • C3D user & customizer
Rename Block on Insert?????
« Reply #20 on: March 16, 2005, 06:00:41 PM »
Mark,
I think that this covers what you want to do.

Code: [Select]
Option Explicit

Sub LegendLayers()
Dim Ent As AcadEntity
Dim BlkDef As AcadBlock
Dim BlkRef As AcadBlockReference
Dim layer As AcadLayer
Dim layers As AcadLayers
Dim blkName As String
Dim space As AcadObject

If ThisDrawing.GetVariable("cvport") = 1 Then
    Set space = ThisDrawing.PaperSpace
Else
    Set space = ThisDrawing.ModelSpace
End If

Set Ent = space.Item(space.Count - 1)
If TypeOf Ent Is AcadBlockReference Then
    Set BlkRef = Ent
    blkName = BlkRef.Name & "-" & BlkRef.XScaleFactor
    On Error Resume Next
    Set BlkDef = ThisDrawing.Blocks.Item(blkName)
    If Err Then 'this will tell if the block has been inserted at this scale _
                already and will only run the block & layer rename if it is the first one
        Set BlkDef = ThisDrawing.Blocks.Item(BlkRef.Name)
        BlkDef.Name = blkName
       
         Set layers = ThisDrawing.layers
        'Use the scale factor of the inserted block to suffix the existing layer names
        'Legend Blocks Layers
         For Each layer In layers
           Select Case layer.Name
             Case Is = ("BA-SYMB")
               layer.Name = ("BA-SYMB") & "-" & BlkRef.XScaleFactor
             Case Is = ("CA-SYMB")
               layer.Name = ("ADT-CA-SYMB") & "-" & BlkRef.XScaleFactor
             Case Is = ("D-SYMB")
               layer.Name = ("D-SYMB") & "-" & BlkRef.XScaleFactor
             Case Is = ("FA-SYMB")
               layer.Name = ("FA-SYMB") & "-" & BlkRef.XScaleFactor
             Case Is = ("I-SYMB")
               layer.Name = ("I-SYMB") & "-" & BlkRef.XScaleFactor
             Case Is = ("TV-SYMB")
               layer.Name = ("TV-SYMB") & "-" & BlkRef.XScaleFactor
         'Text Layers
             Case Is = ("BA-SYMB-TEXT")
               layer.Name = ("BA-SYMB-TEXT") & "-" & BlkRef.XScaleFactor
             Case Is = ("CA-SYMB-TEXT")
               layer.Name = ("CA-SYMB-TEXT") & "-" & BlkRef.XScaleFactor
             Case Is = ("D-SYMB-TEXT")
               layer.Name = ("D-SYMB-TEXT") & "-" & BlkRef.XScaleFactor
             Case Is = ("FA-SYMB-TEXT")
               layer.Name = ("FA-SYMB-TEXT") & "-" & BlkRef.XScaleFactor
             Case Is = ("I-SYMB-TEXT")
               layer.Name = ("I-SYMB-TEXT") & "-" & BlkRef.XScaleFactor
             Case Is = ("TV-SYMB-TEXT")
              layer.Name = ("TV-SYMB-TEXT") & "-" & BlkRef.XScaleFactor
           End Select
          Next
          BlkRef.layer = BlkDef.Item(0).layer 'put the insert on the same layer defined in the block
    Else 'just rename the insert to match the name & scale
        BlkRef.Name = blkName
        BlkRef.layer = BlkDef.Item(0).layer 'put the insert on the same layer defined in the block
    End If
End If
End Sub        

ML

  • Guest
Rename Block on Insert?????
« Reply #21 on: March 17, 2005, 06:54:56 AM »
Hey Jeff

I really appreciate your help man!

I have tried your code and it seems to be working perfectly now!

I need to look at the code closely and see where exactly I was going wrong.

Below is one of about 12 menu macros that we will use to pull the block into the drawing. When I was using Intercomm, we were bringing 4 legends in individually, now we built the whole kit in one drawing.

The below code will load and run the macro, at the end of the macro I will enter a line for unloading (UnloadDVD) the macro after the block is inserted

Thanks again.

Hope I can assist you one of these days

Mark

Code: [Select]

^C^C-insert;LEGEND-KIT;s;48;\;^C^C-vbaload;K:/"path to block";^C^C-vbarun;LegendLayers

ML

  • Guest
Rename Block on Insert?????
« Reply #22 on: March 18, 2005, 07:09:35 AM »
OK Jeff,

It seems to working great, thanks again.
I added a few more things,
I created a variable X for XScalefactor and put in my UnloadDVD command at the end, Variable File

Now, it is precisely what I wanted

Now I can move onto the next headache, I mean challenge   :lol:


Mark


Code: [Select]

Sub LegendLayers()


Dim Ent As AcadEntity
Dim BlkDef As AcadBlock
Dim BlkRef As AcadBlockReference
Dim Layer As AcadLayer
Dim Layers As AcadLayers
Dim BlkName As String
Dim Space As AcadObject
Dim File As String
Dim X As Double


File = "Path\Legends.dvb"    '<-- Path to VBA Project


If ThisDrawing.GetVariable("cvport") = 1 Then
  Set Space = ThisDrawing.PaperSpace
Else
  Set Space = ThisDrawing.ModelSpace
End If

Set Ent = Space.Item(Space.Count - 1)

If TypeOf Ent Is AcadBlockReference Then
      Set BlkRef = Ent
      X = BlkRef.XScaleFactor
      BlkName = BlkRef.Name & "-" & X
   
     On Error Resume Next
   
     Set BlkDef = ThisDrawing.Blocks.Item(BlkName)
               
     If Err Then
      Set BlkDef = ThisDrawing.Blocks.Item(BlkRef.Name)
      BlkDef.Name = BlkName
       
     Set Layers = ThisDrawing.Layers
 
    'Use the scale factor of the inserted block to suffix the existing layer names
    'Legend Blocks Layers
     For Each Layer In Layers
       Select Case Layer.Name
         Case Is = ("BA-SYMB")
           Layer.Name = ("BA-SYMB") & "-" & X
         Case Is = ("CA-SYMB")
           Layer.Name = ("CA-SYMB") & "-" & X
         Case Is = ("D-SYMB")
           Layer.Name = ("D-SYMB") & "-" & X
         Case Is = ("FA-SYMB")
           Layer.Name = ("FA-SYMB") & "-" & X
         Case Is = ("I-SYMB")
           Layer.Name = ("I-SYMB") & "-" & X
         Case Is = ("TV-SYMB")
           Layer.Name = ("TV-SYMB") & "-" & X
         'Text Layers
         Case Is = ("BA-SYMB-T")
           Layer.Name = ("BA-SYMB-T") & "-" & X
         Case Is = ("CA-SYMB-T")
           Layer.Name = ("CA-SYMB-T") & "-" & X
         Case Is = ("D-SYMB-T")
           Layer.Name = ("D-SYMB-T") & "-" & X
         Case Is = ("FA-SYMB-T")
           Layer.Name = ("FA-SYMB-T") & "-" & X
         Case Is = ("I-SYMB-T")
           Layer.Name = ("I-SYMB-T") & "-" & X
         Case Is = ("TV-SYMB-T")
           Layer.Name = ("TV-SYMB-T") & "-" & X
       End Select
     Next
   Else
         'just rename the insert to match the name & scale
         BlkRef.Name = BlkName
   End If
 
End If
        'UnloadDVB File
     
End Sub