Need a Script

Discussion in 'AutoCAD' started by A-Design, Nov 4, 2004.

  1. A-Design

    A-Design Guest

    Hi,

    I need a sample of a script that can filter some objects (like all yellow
    lines or all texts), then make a layer and put all of these objects on this
    layer.
    Can any one give me a sample please?

    Thanks,
    Afshin
     
    A-Design, Nov 4, 2004
    #1
  2. A-Design

    A-Design Guest

    I have looked for it but I couldn't find any script that shows how to use
    the filter command,all I found was VBA and LISP ,can anyone send me a sample
    please? even a complete VBA is okay. Appreciate your help,
     
    A-Design, Nov 4, 2004
    #2
  3. A-Design

    Ed Jobe Guest

    You don't use the FILTER command, you use the filter argument of a method
    that creates a selection set. You can look in help under the Selectionset
    object for examples in addition to what you find here. Search this ng for
    "selectionset filter".
     
    Ed Jobe, Nov 5, 2004
    #3
  4. A-Design

    bcoward Guest

    I'm waiting for a copy-coder to flame up over "really, it's been covered many times, search the archives"

    I'm seeing a lot of issues where people don't find what they want because they might not understand the vocabulary or the object model.

    Wonder what the problem is....
     
    bcoward, Nov 5, 2004
    #4
  5. A-Design

    A-Design Guest

    Thanks Ed,

     
    A-Design, Nov 5, 2004
    #5
  6. Wonder what the problem is....

    The problem is... laziness

    The search subject has already been suggested by Ed.

    Don't expect to get a complete solution to your problems here.
    You still have to read the manuals, the help, search, and research
    and of course, experiment with the code.
     
    Jorge Jimenez, Nov 5, 2004
    #6
  7. A-Design

    bcoward Guest

    Yep...copy-coders don't read. Only the code they think will work.

    Poor foundations can't support poorly prepared academics. I still se it with AutoCAD users that start a new job only to be fired in the week. They search and search the menu for that bitmap because they expelled the benefit of typing on the command line when preparing their foundation.

    With as many people in this industry that call themselves programmers my phone should never ring. I guess there are some I should thank.

    Regards,

    Bob Coward
    CADS, Inc

    800-366-0946
     
    bcoward, Nov 5, 2004
    #7
  8. A-Design

    A-Design Guest

    Dear Friends,



    I have read this article and I would like to say something as well, I am new
    in VBA, this is the way that I have decided to learn VBA ,little by little
    by just copying the codes and changing them a bit to work for me, normally I
    don't do drafting and I don't have time to sit and play with codes, I am a
    designer and I have lots of other things to do, I am not programmer and I
    don't call myself programmer "yet", is not fair to use some word for some
    people (like lazy) just because they don't behave like the way you think
    they have to , before you tell your opinion about others you need to have
    some information about them like their jobs or knowledge and ETC.? Some
    people are just too busy. Thanks,



    Afshin.
     
    A-Design, Nov 5, 2004
    #8
  9. This is not such a good place to start
    learning how to program AutoCAD. This is a place
    where you could find answers to some typical problems
    you may encounter while programming and get stuck,
    ask for advice and tips, etc.

    If you are looking for ready made scripts
    may I suggest the AutoCAD general forum and
    some of the AutoCAD related sites, where many
    free scripts can be found.

    And if you're short of time, you are making a terrible
    mistake trying to learn how to program AutoCAD
    little by little and copying code. You're wasting your
    valuable time this way.
    It will take you far more time to learn
    it this way than it would taking a short course.


    And about the lazyness:

    Laziness...is when you post a message asking for someone to do the job for
    you.

    Busy is everybody in this NG.
    What??, you think you're the only one in this NG
    that has to work overtime and on weekends, and at home ??
    I also need 48 hour days !!

    Now, don't feel offended. This was a general comment
    for many people who post here demanding fast answers.

    Lazyness has grown at the same pace as the internet.
    You see, some people don´t even feel they are
    being lazy when they demand information over
    the web.
    And now, some even get annoyed if no one answers
    giving them what they want. !!
     
    Jorge Jimenez, Nov 5, 2004
    #9
  10. A-Design

    bcoward Guest

    I completely disagree with you. What you have explained is no difference from the way this 9th grade dropout has learned to get by and most on this NG. The big difference I'm sure is how much text has been read, the ability to know how to search, and the common scense to work with it.

    Yes people are lazy. You, me, he, she, and it
     
    bcoward, Nov 5, 2004
    #10
  11. The big difference I'm sure is how much text has been read, the ability to
    I don't see how you completely disagree when you state your "big
    difference".
    That translates into a greater amount of time needed to learn, which is what
    I said.

    I did not state it can't be done that way.
    I was just pointing out, to a time stressed worker
    that the method chosen was a big mistake.
     
    Jorge Jimenez, Nov 6, 2004
    #11
  12. A-Design

    Ed Jobe Guest

    Some of what you say is true as far as the facts that you've observed, but
    may be a bit harsh or inappropriate to say "a big mistake" when talking
    about motives. For example, I read several books, help files and onlline
    resources to learn vb, but currently I don't have the resources to do that
    for .Net. I don't have a choice but to learn it a little at a time. Which
    translates to, I learn how to do each task as I need it. Not the way I'd
    like to learn, but can you say its a "mistake"? Not optimal, for sure, but
    to say "mistake" implies an ignorant or "lazy" decision. My decsion was
    chosen as the most appropriate option for my current circumstances. I hope
    that later I'll be able to invest more time, but until then, I just have to
    make do with what I have. If I were lazy, I wouldn't program at all.

    Monitoring this ng for several years, I do, however, stop at the
    "will-you-write-it-for-me" request. You can usually tell the difference when
    someone's trying to learn and they're doing the work themselves or when they
    just want you do to it for them. The difference might be in "I'm not a
    programmer, but I need ...Do you have it?" vs. "I've trying to learn but
    don't have a clue where to start." In the latter case, I might point them to
    a help file, as I did with Afshin. In the former case, if I answer at all, I
    might just ask them what work have they done on it so far, suggesting that
    they can't *expect* someone to do it for them. Some nice people here have
    volunteered to do entire projects. That's their choice. But people here
    shouldn't *expect* it, which asking for freebies implies. Since this is a
    programmer's group, they should at least be attempting to program. I
    wouldn't walk into a garage and ask the mechanic to work on my car for free,
    but they usually don't mind me asking them some advice on fixing my own car.
     
    Ed Jobe, Nov 6, 2004
    #12
  13. A-Design

    lorier Guest

    Geez, what was the subject of this post?

    Afshin, if you're looking for a script then you are probably in the wrong newsgroup. If VBA is acceptable (this would be relatively easy in VBA) then attempt what you can do. Post it and ask for suggestions.

    Good luck
     
    lorier, Nov 6, 2004
    #13
  14. I wonder if there is something wrong with my news reader.
    How come I don´t read what you read in my posts ??

    I'll repeat what I said:

    "And if you're short of time, you are making a terrible
    mistake trying to learn how to program AutoCAD
    little by little and copying code. You're wasting your
    valuable time this way.
    It will take you far more time to learn
    it this way than it would taking a short course."

    I said "if you're short of time" (or short on time)
    "you are making a terrible mistake" (terrible because
    more time will be needed this way, and he is short
    of it, making his time shortage even bigger)

    I did not mention any motives, except time, because that
    is what he explains in his post.
    He DID NOT talk about lack of any other resources
    so my comment was based on that.

    I DID NOT SAY it wasn't a valid way to learn.
    I DID NOT SAY people learning that way were lazy.
    I DID NOT SAY programmers are lazy
    I DID NOT SAY he was lazy
    I DID NOT SAY you were lazy
    I DID NOT SAY you weren't lazy (just kidding :>)

    As you said yourself, for many reasons one could choose
    to do it that way, but if that reason is time, then I stand by my words.

    You tell me, what advice would you give to someone that
    has very little time and needs to learn a programming language ??
     
    Jorge Jimenez, Nov 6, 2004
    #14
  15. A-Design

    A-Design Guest

    With all respect to readers and professionals on this forum like ED,

    First of all I apologize for my bad English ,it is like my VBA, I'm learning
    it little by little ,but I'll try my best to explain what I am trying to.

    I am also sorry for the late response as I mentioned I don't have much time
    to sit here and argue with people who don't know their rights.



    Dear Jorge and Bob,

    Who gives you the right to judging and assaulting people like the way you
    do?

    Did I ask you to teach me VBA or tell me how and where to learn it? (I asked
    that long time ago when you didn't know about this discussion group).

    Any bodies push you to sit here 24 hr to answer people?

    If I offered money to answer my questions would you still call me lazy? Or
    you would say thanks for your business? Is this the way you treating your
    client in place that you are working in?

    You have to learn to respect other people even if they don't know anything
    about any thing.

    Would you like me to send my resume to you to see how many engineering's
    degree do I have and how many and what kind of software I am working with?
    (Then I am sure you won't call me lazy).

    Some people in this forum love to help others and as ED mentioned they do
    this voluntarily, if my question is not suitable for this group you and
    others could simply tell me that I have to send it somewhere else.

    I didn't know that there is some patrol keep watching this discussion group
    to tell others what they have to do and what they don't have to do!

    I will post my questions here and in other groups in the future, and readers
    have their own rights and freedom to give me an answer or not, I have never
    been demanding and I won't be because even talking about being demanding
    here is funny, I always ask and answer with respect.

    And finally because this is not a good place for arguing I wont continue
    this conversation in the future.



    Thanks,

    Afshin
     
    A-Design, Nov 6, 2004
    #15
  16. A-Design

    bcoward Guest

    J,

    Sorry I clicked in the wrong spot. My disagreement was to A's comments in context.

    I agree completely with you and often agree with your posts.

    Well its 10pm EST and since I need to write some OWA it's time to refresh myself using the outlook vba object modal and it's properties and methods. Reading past midnight, guess that is what it takes sometime.
     
    bcoward, Nov 6, 2004
    #16
  17. Sorry you misunderstood my advice.
    Not that you care, but I'll make sure
    not to give you any more in the future


    Don't waste gestures on eyes that won't see
    Don't waste words on ears that won't hear
    Don't waste ideas on minds that won't think.
    (chinese proverb...300BC)
     
    Jorge Jimenez, Nov 6, 2004
    #17
  18. A-Design

    Jeff Mishler Guest

    And since you asked for some sample code, (and even said "Please") here is
    just that, a sample you can expand upon:

    Option Explicit
    Private Sub GetYellowLines()

    Dim aCod(1) As Integer, aVal(1) As Variant
    Dim oSet As AcadSelectionSet
    Dim eEnt As AcadEntity
    Dim oLay As AcadLayer

    aCod(0) = 0: aVal(0) = "LINE"
    aCod(1) = 62: aVal(1) = 2 '2 for yellow
    Set oSet = SelSetInit("ssLines")
    oSet.Select acSelectionSetAll, , , aCod, aVal

    If oSet.Count > 0 Then
    Set oLay = ThisDrawing.Layers.Add("YellowLines")
    oLay.Color = acYellow
    For Each eEnt In oSet
    eEnt.Layer = "yellowLines"
    eEnt.Color = acByLayer
    Next
    End If

    Set eEnt = Nothing: Set oSet = Nothing
    End Sub

    'Code obtained from the 'Net, author unknown
    Private Function SelSetInit(sName As String) As AcadSelectionSet
    Dim oRetVal As AcadSelectionSet
    On Error GoTo DeleteAndAdd
    Set oRetVal = ThisDrawing.SelectionSets.Add(sName)
    Set SelSetInit = oRetVal
    Exit Function
    DeleteAndAdd:
    ThisDrawing.SelectionSets.Item(sName).Delete
    Set oRetVal = ThisDrawing.SelectionSets.Add(sName)
    Set SelSetInit = oRetVal
    End Function

    Good Luck and don't hesitate to ask for any additional help you may need,
     
    Jeff Mishler, Nov 6, 2004
    #18
  19. A-Design

    bcoward Guest

    A,

    Hopefully you didn't take these comments as directed at you. We who have been around a day or two often loose sight of simplicity.

    So in example of those comments this is how I would solve your request if I'm new to an object modal.

    1 - I need a bunch of stuff. But what I get I want to do something with it. At this time I don't know if I will need X and Y or just X or Y. I'll deal with this later.

    2 - With this stuff I want to make a layer. Hmmm, if I add the layer will it error. Oh well I'll deal with that in step two.

    3 - Put all the objects on this layer. just put them there...sounds like I'm going to take my stuff and change the layer property for this stuff.

    4 - Do I care about performance, memory footprint, or even good code. heck, I just want it to work.

    I need to group stuff or filter stuff. Ever since AutoLisp I remembered that we gathered stuff either by table search or a selection set. I'll check help and see what it says. But not being well versed in how to search help how can I go directly to my topic?

    I go to my IDE

    I insert a module

    I add Sub Main() to my module

    Within sub main I type Dim ObjSS as AcadSelectionSet. While my cursor is at the end of the line I arrow back a couple characters and hit F1. I'm now at the SelectionSet Object in the help files. I see some methods that sound like they might be useful to me: AdddItem, Clear, Delete, Erase. I take some time to read each of these and look at any examples. I'm looking for a pattern that I'll recognize the next time I need to use this. The only thing I don't know at this point is what DXF codes will I be working with. I'll try an experiement, At the command line I'll type (entget(entlast)). I make a note on my scratch pad (0 . "LINE" and 8 . "0"). Maybe 100 . "AcDbLine" might be useful so I scratch that down also. After looking at my scratch pad I'm wondering if 0 . "TEXT" might be useful...I make a note

    I think I'm ready to try and get my stuff. After many trials and bounces through the help files this is what I come up with.

    Option Explicit

    Sub main()
    GetMyStuff "MyNewStuffLayer"
    End Sub

    Public Sub GetMyStuff(strLayer As String)

    Dim ObjSS As AcadSelectionSet
    Dim ObjLayer As AcadLayer
    Dim I As Integer

    Set ObjSS = ciSSDel("temp")

    Dim intType(0) As Integer
    Dim varData(0) As Variant

    intType(0) = 0
    varData(0) = "LINE"

    ObjSS.Select acSelectionSetAll, filtertype:=intType, filterdata:=varData

    ' adding my layer so I can work with it.
    ' by adding it an existing layer is no problem

    Set ObjLayer = ThisDrawing.Layers.Add(strLayer)

    ' Now I can change my stuff

    If ObjSS.Count > 0 Then
    For I = ObjSS.Count To 0 Step -1
    ObjSS.Highlight True
    ObjSS.Item(I).Layer = strLayer
    ObjSS.Update
    ObjSS.Highlight False
    Next I
    End If

    Set ObjSS = Nothing
    Erase intType
    Erase varData

    End Sub

    Private Function ciSSDel(strName As String) As AcadSelectionSet

    ' Check Selection Set Name

    Dim ObjSS As AcadSelectionSet
    Dim objSSets As AcadSelectionSets

    Set objSSets = ThisDrawing.SelectionSets
    For Each ObjSS In objSSets
    If ObjSS.Name = strName Then
    objSSets.Item(strName).Delete
    Exit For
    End If
    Next
    Set ObjSS = objSSets.Add(strName)
    Set ciSSDel = ObjSS

    End Function


    After all the gibberish I hope this helps. Put this code into your code library, you'll use it a thousand times.

    Regards,

    Bob Coward
    CADS, Inc

    800-366-0946
     
    bcoward, Nov 6, 2004
    #19
  20. A-Design

    bcoward Guest

    You can call me if you have a complaint. 800-366-0946
     
    bcoward, Nov 6, 2004
    #20
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.