Computer Aided Design

You are not logged in. [ Login ] Why log in
(NOTE: Login is not required to post)

VBA Alphacam

6/17/17       
Boris van Galvin Member

I have a number of repetitive tasks that I would like to automate and it seems the best way to do this is to create a simple VBA routine and apply them.

The first part of the task is to run a query on the loaded drawing and split it in to Inside and Outside layers. For the example lets say I have two shapes, one is inside the other and I want to drop these on the separate layers then apply a tool path to them individually.

The query is prety simple and works by itself.

Import layers from active drawing (often the file I have has been pulled in from a DXF with no layers)

if (is Inside Another = TRUE)
Then "InsideLayer"
ElseIf (is Inside Another = FALSE)
Then "OutsideLayer"

Next part was to create a simple button to run the query so I dont need to load it every time I want to use it.

Dim Drw As Drawing
Set Drw = App.ActiveDrawing
Drw.RunQuery ("InOutQuery.agq")
End

If I load the drawing the Load the VBA add-In with the button it works fine.
If i then close then drawing and open another drawing then use the button it does not work
If i create a new drawing, put a shape inside another shape the button works fine.

It is almost as if the Geometry layer on the drawing is not being activated or App.ActiveDrawing is being ignored by the simple function when an existing drawing is opened.

6/20/17       #2: VBA Alphacam ...
david wishengrad

It sounds more to me like you have lost connection to the active application.

You should be able to check that with a watch window. Highlight the text for the app in your code and drag and drop it into the watch window (open the watch window if need be), and see if it's active and has data.

It does seem strange. I don't do AlphaCAM VBA, but do understand that the drawing itself (the active document), in a VBA context, is how the code knows the application is there. If it were VB6 then it might be a 'late bound' or 'early bound' issue, but this is VBA. Mike may drop in and answer your question better. I will try and give him a head's up.

"Dim Drw As Drawing", is probably not needed, as whatever the default AlphaCAM object is in the project explorer is, is the default name and document. In AutoCAD VBA it is called "ThisDrawing". When working with multiple documents you will have to explicitly name them and switch between them. You don't note whether or not the code is set to run explicit:

"Option Explicit" at the top sometimes makes it easier to find the bug.

Other than that, I have no idea other than your binding to the application is broken.

6/20/17       #3: VBA Alphacam ...
Boris van Galvin Member

Thank you David for the ideas, will try a few of them and see how they go. It makes sense that the active drawing is some how loosing focus. I'm somewhat new to VB although have programmed in C and a few other languages.

Our new 5 Axis HOMAG just turned up yesterday and is being installed so may be a few days before I get the chance to try a few other things out but will keep everyone posted as to what the issue ends up being.

Totally loving the VB and Alphacam scripting system as it realy does make the creation of commonly used geometries so simple.

6/29/17       #4: VBA Alphacam ...
Marek

Website: http://www.cadcam-softcz.cz

Hi,

send me your macro. I will help you with this.

Marek


Post a Response
  • Notify me of responses to this thread
  • Subscribe to email updates on this Forum
  • To receive email notification of additions to this forum thread,
    enter your name and email address, and then click the
    "Keep Me Posted" button below.

    Please Note: If you have posted a message or response,
    do not submit this request ... you are already signed up
    to receive notification!

    Your Name:
    E-Mail Address:
    Enter the correct numbers into the field below:
     

    Date of your Birth:



    Return to top of page

    Buy & Sell Exchanges | Forums | Galleries | Site Map

    FORUM GUIDELINES: Please review the guidelines below before posting at WOODWEB's Interactive Message Boards (return to top)

  • WOODWEB is a professional industrial woodworking site. Hobbyist and homeowner woodworking questions are inappropriate.
  • Messages should be kept reasonably short and on topic, relating to the focus of the forum. Responses should relate to the original question.
  • A valid email return address must be included with each message.
  • Advertising is inappropriate. The only exceptions are the Classified Ads Exchange, Machinery Exchange, Lumber Exchange, and Job Opportunities and Services Exchange. When posting listings in these areas, review the posting instructions carefully.
  • Subject lines may be edited for length and clarity.
  • "Cross posting" is not permitted. Choose the best forum for your question, and post your question at one forum only.
  • Messages requesting private responses will be removed - Forums are designed to provide information and assistance for all of our visitors. Private response requests are appropriate at WOODWEB's Exchanges and Job Opportunities and Services.
  • Messages that accuse businesses or individuals of alleged negative actions or behavior are inappropriate since WOODWEB is unable to verify or substantiate the claims.
  • Posts with the intent of soliciting answers to surveys are not appropriate. Contact WOODWEB for more information on initiating a survey.
  • Excessive forum participation by an individual upsets the balance of a healthy forum atmosphere. Individuals who excessively post responses containing marginal content will be considered repeat forum abusers.
  • Responses that initiate or support inappropriate and off-topic discussion of general politics detract from the professional woodworking focus of WOODWEB, and will be removed.
  • Participants are encouraged to use their real name when posting. Intentionally using another persons name is prohibited, and posts of this nature will be removed at WOODWEB's discretion.
  • Comments, questions, or criticisms regarding Forum policies should be directed to WOODWEB's Systems Administrator
    (return to top).

    Carefully review your message before clicking on the "Send Message" button - you will not be able to revise the message once it has been sent.

    You will be notified of responses to the message(s) you posted via email. Be sure to enter your email address correctly.

    WOODWEB's forums are a highly regarded resource for professional woodworkers. Messages and responses that are crafted in a professional and civil manner strengthen this resource. Messages that do not reflect a professional tone reduce the value of our forums.

    Messages are inappropriate when their content: is deemed libelous in nature or is based on rumor, fails to meet basic standards of decorum, contains blatant advertising or inappropriate emphasis on self promotion (return to top).

    Libel:   Posts which defame an individual or organization, or employ a tone which can be viewed as malicious in nature. Words, pictures, or cartoons which expose a person or organization to public hatred, shame, disgrace, or ridicule, or induce an ill opinion of a person or organization, are libelous.

    Improper Decorum:   Posts which are profane, inciting, disrespectful or uncivil in tone, or maliciously worded. This also includes the venting of unsubstantiated opinions. Such messages do little to illuminate a given topic, and often have the opposite effect. Constructive criticism is acceptable (return to top).

    Advertising:   The purpose of WOODWEB Forums is to provide answers, not an advertising venue. Companies participating in a Forum discussion should provide specific answers to posted questions. WOODWEB suggests that businesses include an appropriately crafted signature in order to identify their company. A well meaning post that seems to be on-topic but contains a product reference may do your business more harm than good in the Forum environment. Forum users may perceive your references to specific products as unsolicited advertising (spam) and consciously avoid your web site or services. A well-crafted signature is an appropriate way to advertise your services that will not offend potential customers. Signatures should be limited to 4-6 lines, and may contain information that identifies the type of business you're in, your URL and email address (return to top).

    Repeated Forum Abuse: Forum participants who repeatedly fail to follow WOODWEB's Forum Guidelines may encounter difficulty when attempting to post messages.

    There are often situations when the original message asks for opinions: "What is the best widget for my type of shop?". To a certain extent, the person posting the message is responsible for including specific questions within the message. An open ended question (like the one above) invites responses that may read as sales pitches. WOODWEB suggests that companies responding to such a question provide detailed and substantive replies rather than responses that read as a one-sided product promotion. It has been WOODWEB's experience that substantive responses are held in higher regard by our readers (return to top).

    The staff of WOODWEB assume no responsibility for the accuracy, content, or outcome of any posting transmitted at WOODWEB's Message Boards. Participants should undertake the use of machinery, materials and methods discussed at WOODWEB's Message Boards after considerate evaluation, and at their own risk. WOODWEB reserves the right to delete any messages it deems inappropriate. (return to top)


  • Forum Posting Help
    Your Name The name you enter in this field will be the name that appears with your post or response (return to form).
    Your Website Personal or business website links must point to the author's website. Inappropriate links will be removed without notice, and at WOODWEB's sole discretion. WOODWEB reserves the right to delete any messages with links it deems inappropriate. (return to form)
    E-Mail Address Your e-mail address will not be publicly viewable. Forum participants will be able to contact you using a contact link (included with your post) that is substituted for your actual address. You must include a valid email address in this field. (return to form)
    Subject Subject may be edited for length and clarity. Subject lines should provide an indication of the content of your post. (return to form)
    Thread Related Link and Image Guidelines Thread Related Links posted at WOODWEB's Forums and Exchanges should point to locations that provide supporting information for the topic being discussed in the current message thread. The purpose of WOODWEB Forums is to provide answers, not to serve as an advertising venue. A Thread Related Link that directs visitors to an area with inappropriate content will be removed. WOODWEB reserves the right to delete any messages with links or images it deems inappropriate. (return to form)
    Thread Related File Uploads Thread Related Files posted at WOODWEB's Forums and Exchanges should provide supporting information for the topic being discussed in the current message thread. Video Files: acceptable video formats are: .MOV .AVI .WMV .MPEG .MPG .MP4 (Image Upload Tips)   If you encounter any difficulty when uploading video files, E-mail WOODWEB for assistance. The purpose of WOODWEB Forums is to provide answers, not to serve as an advertising venue. A Thread Related File that contains inappropriate content will be removed, and uploaded files that are not directly related to the message thread will be removed. WOODWEB reserves the right to delete any messages with links, files, or images it deems inappropriate. (return to form)