CAD Forum - tips, tricks, discussion and utilities for AutoCAD, Inventor, Revit and other Autodesk products [www.cadforum.cz] ARKANCE | CONTACT - CZ | SK | EN | DE
Over 1.096.000 registered users (EN+CZ). AutoCAD tips, Inventor tips, Revit tips. Try the new precise Engineering calculator and the updated Barcode generator. New AutoCAD 2026 commands and variables.
RSS channel - CAD tips RSS tips
RSS discussions

Discussion Discussion forum

?
CAD discussions, advices, exchange of experience

CAD Forum - Homepage CAD discussion forum - ask any CAD-related questions here, share your CAD knowledge on AutoCAD, Inventor, Revit and other Autodesk software with your peers from all over the world. To start a new topic, choose an appropriate forum.

Please abide by the rules of this forum.
This is a peer-to-peer forum. The forum doesn't replace the official direct technical support provided by ARKANCE for its customers.
How to post questions: register or login, go to the specific forum and click the NEW TOPIC button.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Topic ClosedChanging layer names via a database

 Post Reply Post Reply
Author
GaryM View Drop Down
Newbie
Newbie


Joined: 20.Aug.2007
Location: South Africa
Status: Offline
Points: 16
Direct Link To This Post Topic: Changing layer names via a database
    Posted: 31.Aug.2007 at 11:16
Hey guys

Working on a project where i need to connect to a access database and change layer names in the drawing to a new layer name. The database got a table with a LDN field(Old Layer) and a Proposed_Layer field(New Layer).

Before changing the layers i want it to check its status for example; if its locked etc.

The code is as follows, but seem to get a Compile error: Do without Loop

Private Sub CommandButton1_Click()
'declare variables
Dim oAccess As New ADODB.Connection
Dim strConn As String
Dim CHGLAY As Recordset
Dim LayCnt As Integer
Dim X As Integer
Dim Y As Integer
Dim LaySet As AcadSelectionSet
Dim FilterType(0) As Integer
Dim FilterData(0) As Variant
Dim Ent As AcadEntity
Dim ConVLay As Boolean
Dim Layfal As Integer 'thats layer false

'initiate layer count

LayCnt = ThisDrawing.Layers.Count

'set connection string
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
             "Data Source=" & "E:\Standards.mdb" & ";"

'make connection to database
Set oAccess = CreateObject("ADODB.Connection")
oAccess.Open strConn

CHGLAY.Open "Select !LDN & !Proposed_Layer from MS_Layers Where Len(!LDN)>0)"

Layfal = 0

Y = 0
For Y = 0 To LayCnt - 1
  'check if layers are locked
  ConVLay = False
Next
    If ThisDrawing.Layers.Item(Y).Lock = True Then
      ConVLay = True
    Else

      CHGLAY.MoveFirst
        Do Until CHGLAY.EOF
          If UCase(ThisDrawing.Layers.Item(Y).Name) + UCase(CHGLAY!LDN) Then
            X = 0
              For X = 0 To LayCnt - 1
                If UCase(ThisDrawing.Layers.Item(X).Name) = UCase(CHGLAY!Proposed_Layer) Then
                 
                  FilterType(0) = 8
                  FilterData(0) = ThisDrawing.Layers.Item(Y).Name
                                 
                  Set LaySet = ThisDrawing.SelectionSets.Add("LayerChange")
                 
                  LaySet.Select acSelectionSetAll, , , FilterType, FilterData
             
                    For Each Ent In LaySet
                      Ent.Layer = ThisDrawing.Layers.Item(X).Name
                    Next
                      ThisDrawing.SelectionSets.Item("LayerChange").Delete
                     
                      ConVLay = True
                      Exit For
                      End If
                    Next
                   
                      If ConVLay = False Then
                        CHGLAY.MoveFirst
                          Do Until CHGLAY.EOF
                            If UCase(ThisDrawing.Layers.Item(Y).Name) = UCase(CStr(CHGLAY!Proposed_Layer)) Then
                              ConVLay = True
                            Exit Do
                            End If
                          CHGLAY.MoveNext
                          Loop
                      End If
                     
                      If ConVLay = True Then
                        ThisDrawing.Layers.Item(Y).LayerOn = False
                      ElseIf ConVLay = False Then
                        Layfal = Layfal + 1
                       
                        ThisDrawing.Layers.Item(Y).LayerOn = True
                      End If
                                     
                      If Layfal = 0 Then
                   
                        Else
                          ReDim arrLay(0 To Layfal - 1) As Variant
                            Y = 0
                            X = 0
                   
                    For Y = 0 To LayCnt - 1
                      If ThisDrawing.Layers.Item(Y).LayerOn = True Then
                        arrLay(X) = ThisDrawing.Layers.Item(Y).Name
                        X = X + 1
                      End If
                    Next
                   
                    LstErrLay.List() = arrLay
                     
                      End If
                   
                    CHGLAY.Close
                    oAccess.Close

    ThisDrawing.PurgeAll
    ThisDrawing.Application.Update
    ThisDrawing.Regen acAllViewports
    ThisDrawing.Application.ZoomExtents

    ThisDrawing.SetVariable "FIELDEVAL", 23
    ThisDrawing.SetVariable "USERI5", 99

  MsgBox "DONE!"
End If
End Sub


Regards,
Gary Mansfield
Back to Top
Vladimir Michl View Drop Down
Moderator Group
Moderator Group

Arkance Systems CZ

Joined: 26.Jul.2007
Location: Czech Republic
Using: Autodesk software
Status: Offline
Points: 2121
Direct Link To This Post Posted: 31.Aug.2007 at 11:30
Yes, your outer Do doesn't end with a Loop.
 
You can also try our RNL.LSP - see:
Vladimir Michl (moderator)
ARKANCE - https://arkance.world - Autodesk Platinum Partner
Back to Top
GaryM View Drop Down
Newbie
Newbie


Joined: 20.Aug.2007
Location: South Africa
Status: Offline
Points: 16
Direct Link To This Post Posted: 31.Aug.2007 at 11:52
hey

i cant seem to get that loop at right place.  where exactly is that Do without Loop...
Regards,
Gary Mansfield
Back to Top
Vladimir Michl View Drop Down
Moderator Group
Moderator Group

Arkance Systems CZ

Joined: 26.Jul.2007
Location: Czech Republic
Using: Autodesk software
Status: Offline
Points: 2121
Direct Link To This Post Posted: 31.Aug.2007 at 12:16
Well, every DO must end with a LOOP. I have not looked deeply into your code but you have 2 DOs and a single LOOP only - so there is a syntax error.
Vladimir Michl (moderator)
ARKANCE - https://arkance.world - Autodesk Platinum Partner
Back to Top
GaryM View Drop Down
Newbie
Newbie


Joined: 20.Aug.2007
Location: South Africa
Status: Offline
Points: 16
Direct Link To This Post Posted: 31.Aug.2007 at 14:19
AngryF#@KED!!! it took me 2 hours to get that loop error away.

Big%20smile but it working excellently. COOL MANLOL
Regards,
Gary Mansfield
Back to Top

Related CAD tips:


 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down



This page was generated in 0,076 seconds.