See the top rated post in this thread. Click here

Results 1 to 6 of 6

Thread: Change CAD layer through Excel VBA or LISP

  1. #1
    Login to Give a bone
    0

    Default Change CAD layer through Excel VBA or LISP

    Hi there..

    I am now using AutoCAD 2013.. Is it possible to change hatch layer via excel input through VBA or LISP? Or other methods?

    I have a plaza floor plan with each hatch for each unit (room) to represent unit type. I also have an Excel spreadsheet that contains room number in column A (001, 002, 003,..., etc) and unit type in column B (Small Shop, Food, Hypermarket, Cinema, Department Store, etc).

    Is is possible to update layers in AutoCAD automatically when we change unit type in column B? For example: Unit No. 001 change from Small Shop to Food, and Unit No. 005 change from Hypermarket to Cinema.., and then the layer in AutoCAD updates automatically. The floor plans contains about 300 units and 50 different layers to represent unit type. If this is possible, it would save the amount of time & effort than selecting hatch one by one and change the layer.

    I have never used VBA nor LISP before., but I eager to learn.
    Any clue will be much appreciated..

    Regards,
    Bagus

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    5,571
    Login to Give a bone
    1

    Default Re: Change CAD layer through Excel VBA or LISP

    Yes, its possible in VBA. You can get help here but you need at least some experience with VBA and its IDE. I've written a tutorial. Look for a "Focused VBA" series in the VBA Tutorials sticky thread at the top of this forum.
    C:> ED WORKING....

  3. #3
    Login to Give a bone
    0

    Default Re: Change CAD layer through Excel VBA or LISP

    Thank you Ed for the answer. Okay I will check the tutorial similar to my case.

  4. #4
    Login to Give a bone
    0

    Default Re: Change CAD layer through Excel VBA or LISP

    Quote Originally Posted by bagusdewantoro86762677 View Post
    Hi there..

    I am now using AutoCAD 2013.. Is it possible to change hatch layer via excel input through VBA or LISP? Or other methods?

    I have a plaza floor plan with each hatch for each unit (room) to represent unit type. I also have an Excel spreadsheet that contains room number in column A (001, 002, 003,..., etc) and unit type in column B (Small Shop, Food, Hypermarket, Cinema, Department Store, etc).

    Is is possible to update layers in AutoCAD automatically when we change unit type in column B? For example: Unit No. 001 change from Small Shop to Food, and Unit No. 005 change from Hypermarket to Cinema.., and then the layer in AutoCAD updates automatically. The floor plans contains about 300 units and 50 different layers to represent unit type. If this is possible, it would save the amount of time & effort than selecting hatch one by one and change the layer.

    I have never used VBA nor LISP before., but I eager to learn.
    Any clue will be much appreciated..

    Regards,
    Bagus
    I think I can do it man.
    Last edited by Ed Jobe; 2018-03-01 at 03:28 PM. Reason: Conform to forum guidelines.

  5. #5
    Login to Give a bone
    0

    Default Re: Change CAD layer through Excel VBA or LISP

    Can you post file autocad and Excel for reference?

  6. #6
    Member
    Join Date
    2017-01
    Posts
    8
    Login to Give a bone
    0

    Default Re: Change CAD layer through Excel VBA or LISP

    Sub Change_All_existing_To_Layer()

    Dim ssAll As AcadSelectionSet
    Dim mEntity As AcadEntity, oBlkRef As AcadEntity
    Dim blkAtt As String
    Dim ssets As AcadSelectionSets

    'clear selection set
    Set ssets = ThisDrawing.SelectionSets
    On Error Resume Next
    Set ssAll = ssets.Item("AU2013_SS")
    If Err.Number <> 0 Then
    Set ssAll = ssets.Add("AU2013_SS")
    Else
    ssAll.Clear
    End If
    'selects all entries in drawing
    Set ssAll = ThisDrawing.SelectionSets.Add("AllEntities")
    ssAll.Select acSelectionSetAll

    For Each mEntity In ssAll 'loops thru entry list
    If TypeOf mEntity Is AcadBlockReference Then 'picks blocks
    Set oBlkRef = mEntity
    If oBlkRef.HasAttributes Then 'picks blocks with attributes
    blkAtt = Get_Attribute(oBlkRef, "BLKSET.FURNISH")
    If blkAtt = "\W0.7500;E" Then 'picks "existing" devices
    mEntity.layer = "STAGE.NOTES.SD"
    End If
    End If
    End If
    Next
    ssAll.Clear 'cleans the selection set
    ssAll.Delete
    Set ssAll = Nothing
    ThisDrawing.Regen acActiveViewport 'regenerates the drawing
    End Sub

    this selects all entities in modelspace and then filters them (you would have to change the filter) then changes the layer, is a starting point

Similar Threads

  1. LISP Change layer properties by name filter
    By sanok7728543 in forum AutoLISP
    Replies: 1
    Last Post: 2016-05-25, 11:22 AM
  2. Replies: 4
    Last Post: 2015-02-16, 07:53 PM
  3. Layer Color Change LISP Routine
    By guardianfiredesign774457 in forum AutoLISP
    Replies: 19
    Last Post: 2013-08-28, 05:08 AM
  4. Replies: 17
    Last Post: 2011-11-29, 08:54 PM
  5. Lisp to change layer color in viewport
    By moonlight_9630 in forum AutoLISP
    Replies: 2
    Last Post: 2008-07-08, 07:31 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •