Author Topic: I thought it was easier than this... (newb alert)  (Read 4188 times)

0 Members and 1 Guest are viewing this topic.

Co.Mnstr

  • Guest
I thought it was easier than this... (newb alert)
« 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

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: I thought it was easier than this... (newb alert)
« Reply #1 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
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

Greg B

  • Seagull
  • Posts: 12417
  • Tell me a Joke!
Re: I thought it was easier than this... (newb alert)
« Reply #2 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

Co.Mnstr

  • Guest
Re: I thought it was easier than this... (newb alert)
« Reply #3 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.


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: I thought it was easier than this... (newb alert)
« Reply #4 on: November 13, 2008, 01:56:38 PM »
<Skynard> ♪♫ Ewwww ewww that smell ... cantchu smell that smell ... ♪♫ </Skynard>
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: I thought it was easier than this... (newb alert)
« Reply #5 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!
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

ChuckHardin

  • Guest
Re: I thought it was easier than this... (newb alert)
« Reply #6 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

Greg B

  • Seagull
  • Posts: 12417
  • Tell me a Joke!
Re: I thought it was easier than this... (newb alert)
« Reply #7 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!

Maverick®

  • Seagull
  • Posts: 14778
Re: I thought it was easier than this... (newb alert)
« Reply #8 on: December 03, 2008, 02:24:59 PM »
This isn't Se7en's Chuck is it?

jnieman

  • Guest
Re: I thought it was easier than this... (newb alert)
« Reply #9 on: December 03, 2008, 02:54:34 PM »
oh dear

this was a gem!

ChuckHardin

  • Guest
Re: I thought it was easier than this... (newb alert)
« Reply #10 on: December 03, 2008, 03:24:34 PM »
Do I need to shoot Se7en now?

I guess I just leave a lasting impression.