Changing Hatch PatternScale via ActiveX.

Discussion in 'AutoCAD' started by Bob, Jan 7, 2005.

  1. Bob

    Bob Guest

    After creating some hatch via ActiveX I get errors when I try change the
    patternscale. I've tried this using VLA and VLAX.

    Error I get is:
    ; error: Exception occurred: 0xC0000005 (Access Violation)
    ; warning: unwind skipped on unknown exception

    Works fine if I comment this line out
    (vlax-put-property HObj 'PatternScale 20.0)

    Can anybody help me?

    Thanks,
    Bob
     
    Bob, Jan 7, 2005
    #1
  2. Bob

    BillZ Guest

    Seems to work fine here.

    Used bhatch and hatch command, even solid hatch.

    Bill
     
    BillZ, Jan 7, 2005
    #2
  3. Bob

    Alaspher Guest

    error: Exception occurred: 0xC0000005 (Access Violation)< is internal 'C' error, may occur when error isn't in your code, but is in a C-module (ARX). Try released objects when these more unnecessary.

    Best Regards
     
    Alaspher, Jan 7, 2005
    #3
  4. Bob

    Fatty Guest

    ;Check this example, works fine for me...
    (vl-load-com)
    (setq AcApp (vlax-get-acad-object)
    adoc (vla-get-activedocument AcApp)
    mdsp (vla-get-modelspace adoc))
    (setq pnm "ANSI31" ptyp 0 bas :vlax-true)
    (setq htch (vla-addhatch mdsp 0 pnm bas))
    (setq olp (vlax-ename->vla-object
    (car (entsel "Select outer contour: "))))
    (vla-highlight olp :vlax-true)
    (setq crc (vlax-ename->vla-object
    (car (entsel "Select inner contour: "))))
    (vla-highlight crc :vlax-true)
    (setq hobj (vlax-make-safearray vlax-vbobject '(0 . 0)))
    (vla-appendouterloop htch
    (vlax-safearray-fill hobj (list olp)))
    (vla-appendinnerloop htch
    (vlax-safearray-fill hobj (list crc)))
    (vla-put-PatternScale htch 250.);change 'htch' !!!
    (vla-put-PatternAngle htch (* pi 0.125))
    (vla-highlight olp :vlax-false)
    (vla-highlight crc :vlax-false)
    (vla-evaluate htch)
    (mapcar (function (lambda (x)
    (if (vlax-object-released-p x)
    (vlax-release-object x))))
    (list olp crc htch))
    (vla-regen adoc acActiveViewport)
     
    Fatty, Jan 10, 2005
    #4
  5. Bob

    Bob Guest

    Fatty, Alasher, BillZ:

    Thank you all for responding to my inquiry. I have been able to get this to
    work in the activedocument. What I need to do is get it to work in another
    document other than the activedocument...

    I'm trying to write a program to let me auto-create parts to be used in my
    current drawing session. So, entirely in the background I would like to
    generate the part, hatch it, change the hatch scale, add text, change the
    text alignment, add notation, change object layers, add a titleblock and
    paperspace viewports, wblock out a shop drawing and then insert the finish
    part into my current session. All without ever changing to the other
    drawing session. One would think this is what ActiveX technology is for.
    However, no matter how I do this using vla, vlax, releasing objects, etc. I
    get the following error.

    ; error: Exception occurred: 0xC0000005 (Access Violation)
    ; warning: unwind skipped on unknown exception

    or much worse errors that dump my out of ACAD.

    I'm now about 99% sure this is simply a bug... since it also doesn't work
    for changing the alignment of a text object and in some cases changing the
    layer of just created objects. Hopefully, one of you or somebody else can
    prove me wrong.

    Ciao,
    Bob
     
    Bob, Jan 11, 2005
    #5
  6. Bob

    Jeff Mishler Guest

    Interesting......I can duplicate this in VBA as well....except acad doesn't
    just get unstable, it flat Fatal Errors and quits......

    However, I just tested changing the PatternScale in a document opend via
    ObjectDBX and it worked just fine. The text object still does not update
    correctly though. The properties will change, but the text is displayed
    incorrectly until an edit is made to it in the editor. But after some more
    testing, if the text's insertion point is calculated and set, THEN the text
    is updated properly.

    Here's the VBA code that does work in R2002, it shouldn't be too hard to
    convert this to lisp:

    Sub test()
    Dim doc As AxDbDocument
    Dim obj As AcadEntity
    Dim hatch As AcadHatch
    Dim text As AcadText
    Dim insPt(2) As Double
    Dim textPt(2) As Double
    Dim llPt As Variant
    Dim urPt As Variant
    Dim rot As Double

    Set doc = GetInterfaceObject("ObjectDBX.AxDbDocument")
    doc.Open ("c:\test2000.dwg")
    insPt(0) = 40: insPt(1) = 40
    textPt(0) = insPt(0): textPt(1) = insPt(1): textPt(2) = insPt(2)
    For Each obj In doc.ModelSpace
    If TypeOf obj Is AcadHatch Then
    Set hatch = obj
    hatch.PatternScale = 2#
    End If
    If TypeOf obj Is AcadText Then
    Set text = obj
    rot = text.Rotation
    text.Rotation = 0#
    text.GetBoundingBox llPt, urPt
    text.Alignment = acAlignmentCenter
    text.TextAlignmentPoint = insPt
    textPt(0) = insPt(0) - ((urPt(0) + llPt(0)) / 2)
    'Above only works if using Center alignment
    text.InsertionPoint = textPt
    text.Rotation = rot
    text.Update
    End If
    Next
    doc.SaveAs ("c:\test2000.dwg")
    Set doc = Nothing
    End Sub

    this was tested with the sample drawing Bob created by the code originally
    posted for his TextAlignment problem and I added 1 cloded pline and a hatch
    of that pline.
     
    Jeff Mishler, Jan 11, 2005
    #6
  7. Bob

    BillZ Guest

    Bob,
    I don't know if this is relavent or or not but this is the squence I used because without the vla-evaluate, I could not see any change in the hatch after I set the hatch scale.

    1.) Hatch the rectangle

    Command: bhatch

    Select internal point: Selecting everything...
    Selecting everything visible...
    Analyzing the selected data...

    Analyzing internal islands...

    Select internal point:

    2.) Get object.

    Command: (setq hatchobj (vlax-ename->vla-object (entlast)))
    #<VLA-OBJECT IAcadHatch 09018224>

    3.) Update object.

    Command: (vla-put-patternscale hatchobj 2.0)
    nil

    Command: (vla-evaluate hatchobj)
    nil

    Command: (vla-update hatchobj)
    nil

    I'm kinda new to this vla stuff so not sure about everthing yet.

    From the help files:

    You must re-evaluate a hatch using the Evaluate method to see any edits to the hatch.


    HTH

    Bill
     
    BillZ, Jan 12, 2005
    #7
  8. Bob

    Jeff Mishler Guest

    Bill,
    You are still trying this in the active drawing. The problem arises when you
    are trying to change the scale of a drawing in the background. The error is
    thrown immediately upon issuing the (vla-put-patternscale hatchobj 2.0) when
    working with anything other than the active document.

    Give this a try in MDI mode. (You can't work on a background drawing in SDI,
    unless using ObjectDBX)
    Code:
    (setq ACADObject (vlax-get-acad-object)
    ACADCollection (vlax-get-property ACADObject 'Documents)
    NewDoc (vlax-invoke-method ACADCollection 'Add)
    CModelSpace (vlax-get-property NewDoc 'ModelSpace)
    )
    (setq coords '(20.0 20.0 0.0 40.0 20.0 60.0 40.0 40.0 60.0 20.0))
    (setq pline (vlax-invoke CModelSpace 'addlightweightpolyline coords))
    (vla-put-closed pline :vlax-true)
    (setq hatch (vlax-invoke CModelSpace 'addhatch acHatchPatternTypePredefined
    "ANSI31" :vlax-true))
    (vlax-invoke hatch 'appendouterloop (list pline))
    (vla-evaluate hatch)
    (vlax-put hatch 'patternscale 2.0)
    
     
    Jeff Mishler, Jan 12, 2005
    #8
  9. Bob

    BillZ Guest

    Oooh...

    ; error: Exception occurred: 0xC0000005 (Access Violation)
    ; warning: unwind skipped on unknown exception

    Did the same thing here.

    R2005

    Bill
     
    BillZ, Jan 12, 2005
    #9
  10. Bob

    Jeff Mishler Guest

    Uh, did you zoom extents? The pline & hatch are created outside the default
    view area.......
     
    Jeff Mishler, Jan 12, 2005
    #10
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.