| Author |
Message |
Bob
Guest
|
Posted:
Fri Jan 07, 2005 11:51 pm Post subject:
Changing Hatch PatternScale via ActiveX. |
|
|
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
|
|
| Back to top |
|
 |
BillZ
Guest
|
Posted:
Sat Jan 08, 2005 12:07 am Post subject:
Re: Changing Hatch PatternScale via ActiveX. |
|
|
Seems to work fine here.
Used bhatch and hatch command, even solid hatch.
Bill |
|
| Back to top |
|
 |
Alaspher
Guest
|
Posted:
Sat Jan 08, 2005 1:44 am Post subject:
Re: Changing Hatch PatternScale via ActiveX. |
|
|
| Quote: | 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
|
|
| Back to top |
|
 |
Fatty
Guest
|
Posted:
Mon Jan 10, 2005 3:37 pm Post subject:
Re: Changing Hatch PatternScale via ActiveX. |
|
|
;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) |
|
| Back to top |
|
 |
Bob
Guest
|
Posted:
Tue Jan 11, 2005 10:05 am Post subject:
Re: Changing Hatch PatternScale via ActiveX. |
|
|
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 |
|
| Back to top |
|
 |
Jeff Mishler
Guest
|
Posted:
Tue Jan 11, 2005 11:49 pm Post subject:
Re: Changing Hatch PatternScale via ActiveX. |
|
|
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
check out www.cadvault.com
"Bob" <nospam@nospam.nospam> wrote in message news:41e33fa3$1_2@newsprd01...
| Quote: | 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 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
|
|
|
| Back to top |
|
 |
BillZ
Guest
|
Posted:
Wed Jan 12, 2005 5:06 pm Post subject:
Re: Changing Hatch PatternScale via ActiveX. |
|
|
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 |
|
| Back to top |
|
 |
Jeff Mishler
Guest
|
Posted:
Wed Jan 12, 2005 10:44 pm Post subject:
Re: Changing Hatch PatternScale via ActiveX. |
|
|
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
check out www.cadvault.com
"BillZ" <nospam@address.withheld> wrote in message
news:15234517.1105531641603.JavaMail.jive@jiveforum1.autodesk.com...
| Quote: | 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.
|
|
|
| Back to top |
|
 |
BillZ
Guest
|
Posted:
Thu Jan 13, 2005 12:54 am Post subject:
Re: Changing Hatch PatternScale via ActiveX. |
|
|
Oooh...
; error: Exception occurred: 0xC0000005 (Access Violation)
; warning: unwind skipped on unknown exception
Did the same thing here.
R2005
Bill |
|
| Back to top |
|
 |
BillZ
Guest
|
Posted:
Thu Jan 13, 2005 1:02 am Post subject:
Re: Changing Hatch PatternScale via ActiveX. |
|
|
As far as that goes, when I rem out the last line, i come upo with a blank drawing. No pline or hatch...
Bill
(defun testhatch ()
(setq ACADObject (vlax-get-acad-object)
ACADCollection (vlax-get-property ACADObject 'Documents)
NewDoc (vlax-invoke-method ACADCollection 'Add)
CModelSpace (vlax-get-property NewDoc 'ModelSpace)
)
(command "pause" 10)
(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)
) |
|
| Back to top |
|
 |
Jeff Mishler
Guest
|
Posted:
Thu Jan 13, 2005 1:24 am Post subject:
Re: Changing Hatch PatternScale via ActiveX. |
|
|
Uh, did you zoom extents? The pline & hatch are created outside the default
view area.......
--
Jeff
check out www.cadvault.com
"BillZ" <nospam@address.withheld> wrote in message
news:26418570.1105560153048.JavaMail.jive@jiveforum1.autodesk.com...
| Quote: | As far as that goes, when I rem out the last line, i come upo with a blank
drawing. No pline or hatch...
Bill
(defun testhatch ()
(setq ACADObject (vlax-get-acad-object)
ACADCollection (vlax-get-property ACADObject 'Documents)
NewDoc (vlax-invoke-method ACADCollection 'Add)
CModelSpace (vlax-get-property NewDoc 'ModelSpace)
)
(command "pause" 10)
(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)
) |
|
|
| Back to top |
|
 |
BillZ
Guest
|
Posted:
Thu Jan 13, 2005 1:30 am Post subject:
Re: Changing Hatch PatternScale via ActiveX. |
|
|
Oh yeah,
I (command "pause" 10) instead of (command "delay" 10).
Thats why.
Can't you (vla-zoom obj acAllViews) or something.
I thought I saw that somewhere but can't find it now.
Bill |
|
| Back to top |
|
 |
|
|
|
|