TheSwamp

Code Red => VB(A) => Topic started by: Co.Mnstr on November 13, 2008, 01:14:21 PM

Title: I thought it was easier than this... (newb alert)
Post by: Co.Mnstr on November 13, 2008, 01:14:21 PM
I thought it was easier that this. I have run into a road block and of all the examples I have found this code should work.
Basic, and I mean basic, I want to create two selection sets. I have learned that I need to check if they already exist, and if they do then delete them. Then make the selection sets again. What I want this simple code to do is look into the existing selectionsets and delete any that have the same names as the one I am about to create. Then do a simple display showing me that the selection set that I have created are in the drawing. I will then build my code off that.
Code: [Select]
Sub ChXrefGray()
Dim ASSS as acadselectionsets
Dim Ass, xxreflist, xxlayerlist as acadselectionset
Dim msg as string

Set ASSS = ThisDrawing.SelectionSets
For Each Ass In ASSS
    If Ass.Name = "xreflist" Then
      ASSS.Item("xreflist").Delete
      Else   
    If Ass = "layerlist" Then
      ASSS.Item("layerlist").Delete
      Else   
  End If
Next

Set ssxreflist = ASSS.Add("XrefList")
Set sslayerlist = ASSS.Add("LayerList")

MsgBox "there are " & ThisDrawing.SelectionSets.Count & "Selection Sets in this drawing"
msg = vbCrLf & vbCrLf

For Each Ass In ASSS
    AssName = Ass.Name
    msg = msg & AssName
    msg = msg & vbCrLf
Next

MsgBox msg

End Sub

Can't get more basic. But when I run the code, VB tells me that I have a Next statement with out a For statement. At the very beginning of the code. I hope someone can explain to me why my code does not work, but other examples of the same do.

Thanks all,
Alex
Title: Re: I thought it was easier than this... (newb alert)
Post by: Matt__W on November 13, 2008, 01:18:11 PM
Try this...

Code: [Select]
For Each Ass In ASSS
    If Ass.Name = "xreflist" Then
      ASSS.Item("xreflist").Delete
    ElseIf Ass = "layerlist" Then
      ASSS.Item("layerlist").Delete
  End If
Next
Title: Re: I thought it was easier than this... (newb alert)
Post by: Greg B on November 13, 2008, 01:48:41 PM
Try this...

Code: [Select]
For Each Ass In ASSS
    If Ass.Name = "xreflist" Then
      ASSS.Item("xreflist").Delete
    ElseIf Ass = "layerlist" Then
      ASSS.Item("layerlist").Delete
  End If
Next

 :? :-D
Title: Re: I thought it was easier than this... (newb alert)
Post by: Co.Mnstr on November 13, 2008, 01:55:29 PM
Matt,

Thank you very much. It worked like a charm. I bow down to your kind words of wisdom.

Title: Re: I thought it was easier than this... (newb alert)
Post by: MP on November 13, 2008, 01:56:38 PM
<Skynard> ♪♫ Ewwww ewww that smell ... cantchu smell that smell ... ♪♫ </Skynard>
Title: Re: I thought it was easier than this... (newb alert)
Post by: Matt__W on November 13, 2008, 02:24:10 PM
Try this...

Code: [Select]
For Each Ass In ASSS
    If Ass.Name = "xreflist" Then
      ASSS.Item("xreflist").Delete
    ElseIf Ass = "layerlist" Then
      ASSS.Item("layerlist").Delete
  End If
Next

 :? :-D

 :lmao:  I didn't even see that!
Title: Re: I thought it was easier than this... (newb alert)
Post by: ChuckHardin on December 03, 2008, 02:14:45 PM
Just looking around and saw this post. I can't believe no one offered this code up  :-D

Code: [Select]
Sub ChXrefGray()
Dim ASSS as acadselectionsets
Dim Ass, xxreflist, xxlayerlist as acadselectionset
Dim msg as string

Set ASSS = ThisDrawing.SelectionSets

Set ssxreflist = vbdPowerSet("XrefList")
Set sslayerlist =vbdPowerSet("LayerList")

MsgBox "there are " & ThisDrawing.SelectionSets.Count & "Selection Sets in this drawing"
msg = vbCrLf & vbCrLf

For Each Ass In ASSS
    AssName = Ass.Name
    msg = msg & AssName
    msg = msg & vbCrLf
Next

MsgBox msg

End Sub



'From The Llama Library Published November 12, 1999
Function vbdPowerSet(strName As String) As AcadSelectionSet
Dim objSelSet As AcadSelectionSet
Dim objSelCol As AcadSelectionSets
 
 Set objSelCol = Thisdrawing.SelectionSets
 For Each objSelSet In objSelCol
      If objSelSet.Name = strName Then
           objSelCol.Item(strName).Delete
           Exit For
      End If
 Next
 Set objSelSet = objSelCol.Add(strName)
 Set vbdPowerSet = objSelSet

End Function
Title: Re: I thought it was easier than this... (newb alert)
Post by: Greg B on December 03, 2008, 02:21:43 PM
Just looking around and saw this post. I can't believe no one offered this code up  :-D

Code: [Select]
Sub ChXrefGray()
Dim ASSS as acadselectionsets
Dim Ass, xxreflist, xxlayerlist as acadselectionset
Dim msg as string

Set ASSS = ThisDrawing.SelectionSets

Set ssxreflist = vbdPowerSet("XrefList")
Set sslayerlist =vbdPowerSet("LayerList")

MsgBox "there are " & ThisDrawing.SelectionSets.Count & "Selection Sets in this drawing"
msg = vbCrLf & vbCrLf

For Each Ass In ASSS
    AssName = Ass.Name
    msg = msg & AssName
    msg = msg & vbCrLf
Next

MsgBox msg

End Sub



'From The Llama Library Published November 12, 1999
Function vbdPowerSet(strName As String) As AcadSelectionSet
Dim objSelSet As AcadSelectionSet
Dim objSelCol As AcadSelectionSets
 
 Set objSelCol = Thisdrawing.SelectionSets
 For Each objSelSet In objSelCol
      If objSelSet.Name = strName Then
           objSelCol.Item(strName).Delete
           Exit For
      End If
 Next
 Set objSelSet = objSelCol.Add(strName)
 Set vbdPowerSet = objSelSet

End Function

Hey Chuck!
Title: Re: I thought it was easier than this... (newb alert)
Post by: Maverick® on December 03, 2008, 02:24:59 PM
This isn't Se7en's Chuck is it?
Title: Re: I thought it was easier than this... (newb alert)
Post by: jnieman on December 03, 2008, 02:54:34 PM
oh dear

this was a gem!
Title: Re: I thought it was easier than this... (newb alert)
Post by: ChuckHardin on December 03, 2008, 03:24:34 PM
Do I need to shoot Se7en now?

I guess I just leave a lasting impression.