Author Topic: If Layer Exists Then:  (Read 9457 times)

0 Members and 1 Guest are viewing this topic.

Jeff_M

  • King Gator
  • Posts: 3942
  • C3D user & customizer
If Layer Exists Then:
« Reply #30 on: February 21, 2005, 02:26:37 PM »
Mark, after reading your one mention above of why you are going to these measures of wanting the layer renamed:
Quote
The other thing to consider is that the block will be inserted as a non-exploded block but the user will (more then likely) explode it eventually for other reasons.

After the block is exploded, it will then adopt its original layer which was:
Co-I-SYMB

I think that you'd be better served by just placing the block on the desired layer and either redefining the explode command to place the block's objects on the parent's layer or teach your users to use an "explode to layer" command, such as the one included with Express Tools.

I have played around with the ObjectAdded event to create a new block & layer based on the scale but I keep getting errors...."Object was open for read"... when I try to change the newly added object's layer and/or name.

Otherwise, I'm out of ideas. Good luck,
Jeff

ML

  • Guest
If Layer Exists Then:
« Reply #31 on: February 21, 2005, 02:33:11 PM »
Hi Jeff

Yes I was getting the same error, Object was Open for Read

I really appreciate your help.

Well, at least I know that I have tried several options.

This still doesn't explain why I successfully get the first on to work perfectly.

I am also out of ideas.

Thank you again

Mark

ML

  • Guest
If Layer Exists Then:
« Reply #32 on: February 23, 2005, 09:17:46 AM »
Jeff

If you get achance, read this thread at AutoDesk.
It adds insite into this Object was open for read.

THe problem may be that  we are trying to use Block Reference to put the Intercomm block onto a layer whereas it may be that we need reference it as an entity instead.

If I get a chance, I will look into it more later

Mark


http://discussion.autodesk.com/thread.jspa?messageID=418549

ML

  • Guest
If Layer Exists Then:
« Reply #33 on: February 23, 2005, 10:12:47 AM »
Hey Seven,

While you are at it, can you post the answers I need??   :D

Thanks

Mark

Jeff_M

  • King Gator
  • Posts: 3942
  • C3D user & customizer
If Layer Exists Then:
« Reply #34 on: February 23, 2005, 05:16:43 PM »
Mark,
I'm not sure how that thread relates to this issue. We are not iterating a selection set, nor are we using r14.

I had tried setting the object to a variable dimensioned as a blockreference with the same result. I think the problem stems from the Event handler has the object open, so a global var would need to be set, checked, then acted upon after the event handler is done. I just don't have the time to play with it at the moment.....maybe over the weekend I'll get some time.

On another note......your last post was directed at Se7en, I haven't seen him post in this thread.....are you seeing things I'm not?  :?

ML

  • Guest
If Layer Exists Then:
« Reply #35 on: February 24, 2005, 03:30:02 PM »
LOL

No, he had a test post on here and said sorry about the post, we will delete it.

So, I said, while you are here, may be you can help :)

Hey Jeff,
Someone directed me to that thread so I thought it might be useful to read. I wasn't sure if it was specifically relevant though the error was the same.

Please don't spend your time off trying to figure out something for me, I will get it.

The things you have posted have already been a big help

ML

  • Guest
If Layer Exists Then:
« Reply #36 on: February 24, 2005, 04:38:56 PM »
Hey Jeff,

I'm sorry,
I accidentally sent you a thread that I was reading but here is the one I meant to send you.

There are 19 posts on Object Open for Read.


http://discussion.autodesk.com/search!execute.jspa?numResults=25&source=forumlist%7C8&q=%22Object+was+open+for+read%22&objID=c8&search=Search

Take it easy

Mark

ML

  • Guest
If Layer Exists Then:
« Reply #37 on: February 24, 2005, 05:32:03 PM »
Ok,

Jeff, I believe I have solved it.
With all of your help and my persistence, this seems to be working real well. Along with The Sset, I used a For, Each Loop and it seems to be working real well.

It looks for the blockreference based on the scale, creates the layer, grabs the block and places it on the newly created layer.

So after the user inserts the block, they need to launch the macro immediately after. That is exactly what I was looking to do.

If you get a chance, get it a shot and let me know what you think

Thanks again

Mark

-------------------------------------

Sub Scaledblockonlayer()

Dim BlkRef As AcadBlockReference
Dim Sset As AcadSelectionSet

Set Sset = ThisDrawing.PickfirstSelectionSet
Sset.Select acSelectionSetLast

 For Each BlkRef In Sset
   Select Case BlkRef.XScaleFactor
    Case Is = 48#
     ThisDrawing.layers.Add ("CO-I-SYMB-48")
     Sset.Item(0).Layer = ("CO-I-SYMB-48")
    Case Is = 96#
     ThisDrawing.layers.Add ("CO-I-SYMB-96")
     Sset.Item(0).Layer = ("CO-I-SYMB-96")
   End Select
 Next
 
 
End Sub

ML

  • Guest
If Layer Exists Then:
« Reply #38 on: February 24, 2005, 05:32:59 PM »
Ok,

Jeff, I believe I have solved it.
With all of your help and my persistence, this seems to be working real well. Along with The Sset, I used a For, Each Loop and it seems to be working real well.

It looks for the blockreference based on the scale, creates the layer, grabs the block and places it on the newly created layer.

So after the user inserts the block, they need to launch the macro immediately after. That is exactly what I was looking to do.

If you get a chance, get it a shot and let me know what you think

Thanks again

Mark

-------------------------------------
Code: [Select]

Sub Scaledblockonlayer()

Dim BlkRef As AcadBlockReference
Dim Sset As AcadSelectionSet

Set Sset = ThisDrawing.PickfirstSelectionSet
Sset.Select acSelectionSetLast

 For Each BlkRef In Sset
   Select Case BlkRef.XScaleFactor
    Case Is = 48#
     ThisDrawing.layers.Add ("CO-I-SYMB-48")
     Sset.Item(0).Layer = ("CO-I-SYMB-48")
    Case Is = 96#
     ThisDrawing.layers.Add ("CO-I-SYMB-96")
     Sset.Item(0).Layer = ("CO-I-SYMB-96")
   End Select
 Next
 
 
End Sub

Jeff_M

  • King Gator
  • Posts: 3942
  • C3D user & customizer
If Layer Exists Then:
« Reply #39 on: February 24, 2005, 07:48:24 PM »
The only thing I see right off the top of my head is that if this is run without the intended blockref visible it may select another block that IS visible. But if this is run immedaitely after visibly inserting a block then that shoudln't be a problem.

I'm glad you got something working though!

Jeff_M

  • King Gator
  • Posts: 3942
  • C3D user & customizer
If Layer Exists Then:
« Reply #40 on: February 24, 2005, 09:13:18 PM »
Well, Mark, I seem to have found another solution for you. Rather than have the user launch another application (who's to say they will always remember to), you said that the block is being insert with a lisp routine, correct? Since VBA has a "EndLisp" event, why not place your code in there?

For instance, your user runs the lisp routine that inserts the block "intercomm1" at 48 scale, once done the event handler will be alerted and this code could run:
Code: [Select]

 'placed in the ThisDrawing module of either the Acad.dvb file or any other dvb that is loaded
Private Sub AcadDocument_EndLisp()
Dim oEnt As AcadEntity
Dim oBlk As AcadBlockReference

With ThisDrawing
    If .GetVariable("cvport") = 1 Then
        Set oEnt = .PaperSpace.Item(.PaperSpace.Count - 1)
    Else
        Set oEnt = .ModelSpace.Item(.ModelSpace.Count - 1)
    End If
    If TypeOf oEnt Is AcadBlockReference Then
        Set oBlk = oEnt
        'you could add a check for block.name here if desired
        Select Case oBlk.XScaleFactor
            Case Is = 48#
            .Layers.Add ("CO-I-SYMB-48")
            oBlk.Layer = ("CO-I-SYMB-48")
           
            Case Is = 96#
            .Layers.Add ("CO-I-SYMB-96")
            oBlk.Layer = ("CO-I-SYMB-96")
               
        End Select
    End If
End With
End Sub


And since I have tested this to work, I'm convinced that the ObjectAdded event failed due to the event itself had the object open for read.

ML

  • Guest
If Layer Exists Then:
« Reply #41 on: February 25, 2005, 07:26:24 AM »
Hey Jeff

I really appreciate it.
Actually I am not using LISP, I am better at and prefer VBA.
I actually use a series of menu macros that are accessed from a company pulldown menu that I created.

Here is an example of the block being inserted at 48:
Code: [Select]

^C^C-insert;Intercomm1;s;48;\;^C^C-vbaload;"C:/Documents and Settings/Mark/Desktop/CO_Legend_Layers1.dvb";-vbarun;CO_LegendLayers;


 The User is prompted for an insertion point on screen, then The VBA Project loads, macro runs, then in the vba module, I use UnloadDVB at the end so that the user or whoever can use it again without having to worry about read-only problems. Also, this guarantees that the macro is fired up "directly" after block insert


As far as my previous post, I am real happy with the results of the code I worked out , but you do raise a good point.

We could set a reference to the specific block or I could also add a line
using  BlkRef.name =

Code: [Select]

 Select Case BlkRef.XScaleFactor
 Case Is = 48#
 Case  BlkRef.name = ("Intercomm1")
 'Add layer code


or

Code: [Select]

 Select Case BlkRef.name = ("Intercomm1")
 Case  BlkRef.XScaleFactor = 48
'Add layer code


I think either method would work to validate the name as well but I need to try it. What do you think?

I will definetely need to add code for that purpose as we will be inserting other blocks as well.

I need to see exactly which way I need to go with this before I get too crazy but this is a great start.

Mark

ML

  • Guest
If Layer Exists Then:
« Reply #42 on: March 01, 2005, 04:41:29 PM »
OK,

Now the code looks for the block reference name first, then scale.
If it finds the name and scale, it then creates the layer and places the block on that layer and makes the layer the necessary color

If the user selects a scale that we don't want to use, then they are notified that it is not a used scale.

I show only scale factor 48 here but the actual module has 14 possible scale factors that the block can be inserted at.

Mark

Code: [Select]

Sub LegendLayers()

Dim BlkRef As AcadBlockReference
Dim Sset As AcadSelectionSet

Set Sset = ThisDrawing.PickfirstSelectionSet
Sset.Select acSelectionSetLast

                 
For Each BlkRef In Sset
  If BlkRef.Name = "Intercomm" Then
    Select Case BlkRef.XScaleFactor
      Case Is = 48#
        ThisDrawing.Layers.Add ("CO-I-SYMB-48")
        Sset.Item(0).Layer = ("CO-I-SYMB-48")
        ThisDrawing.Layers("CO-I-SYMB-48").color = acCyan
      Case Else
       MsgBox "This scale is not used"
     End Select
  End If
             
  If BlkRef.Name = "Fire_Alarm" Then
    Select Case BlkRef.XScaleFactor
      Case Is = 48#
        ThisDrawing.Layers.Add ("CO-FA-SYMB-48")
        Sset.Item(0).Layer = ("CO-FA-SYMB-48")
        ThisDrawing.Layers("CO-FA-SYMB-48").color = acRed
      Case Else
       MsgBox "This scale is not used"
     End Select
  End If
Next


Sset.Delete


ThisDrawing.SendCommand "vbaunload" & vbCr & "CO_Legends" & vbCr


End Sub