Is there a way to Set Clip Boundaries through VBA?
I am trying to loop through my Raster Images to replace them with another image (which is another problem for another post!) then set the clip boundary based on 2 points.
When looking at the options within VBA is looks like it can only be an element. Rather than try to create a new element then remove it i thought i would see if anyone has had any experience with this previously.
I recorded a Macro to try to get some hints but it didn't really help.
I was hoping to use something along the code block below
For i = 0 To RasterManager.Rasters.Count - 1 Set oRaster = RasterManager.Rasters(i) If InStr(oRaster.RasterInformation.Name, "_") > 0 Then oRaster.SetClipBoundary oPoint1, oPoint2 Else oRaster.SetClipBoundary oPoint3, oPoint4 End If oRaster.Reload Next
Using V8i SS10 on Windows 10.
Thanks!
Robert Golding said:Is there a way to Set Clip Boundaries through VBA?
You must call MDL functions for DGN reference files. Here are some hints and sample code.
Robert Golding said:I was hoping to use something along the code block below [for raster attachments] oRaster.SetClipBoundaryRather than try to create a new element then remove it
oRaster.SetClipBoundary
Rather than try to create a new element then remove it
If you create then remove an element programmatically, it will flash so quickly that the user will hardly notice. If you create it using the background colour, even the flash should be invisible.
Regards, Jon Summers LA Solutions
Thanks Jon, this is very helpful!
However i am struggling to get this to work for Rasters. Do you have any tips for getting a Raster object and pass it as an Attachment?
Hi Robert,
Robert Golding said:Do you have any tips for getting a Raster object and pass it as an Attachment?
Jon's article is about attachments (which is a term for attached vector data). Rasters (raster attachments) are completely different objects, managed separately by Raster Manager. So the approach, described in the article, cannot be used for rasters.
Robert Golding said:When looking at the options within VBA is looks like it can only be an element
Yes, even though internally the clip boundary is a list of vertices, in VBA the modification is limited to this method. But where do you see a problem?
Robert Golding said:Rather than try to create a new element then remove it
Why you want to do something else than how VBA API is designed? Plus, why do you want to remove an element? Element must exist (which means, because we are discussing programming API, the object must exist in memory), but it does not require it must be persisted in DGN file.
Did you test how the method works? The code is simple:
Dim vertices(4) As Point3d vertices(1) = Point3dFromXY(-10, -16) vertices(2) = Point3dFromXY(5, -16) vertices(3) = Point3dFromXY(5, -2) vertices(4) = Point3dFromXY(-10, -2) Dim boundary As ShapeElement Set boundary = CreateShapeElement1(Nothing, vertices) Dim rst As raster Set rst = RasterManager.Rasters(1) rst.SetClipBoundary boundary
Robert Golding said:then set the clip boundary based on 2 points.
Set the clip by 2 points is nothing else than specifically created shape element.
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Jan Šlegr said:Jon's article is about attachments (which is a term for attached vector data). Rasters (raster attachments) are completely different objects, managed separately by Raster Manager. So the approach, described in the article, cannot be used for rasters.
The original post asked about Clipping Raster's so I thought there might have been a common way to do either, or to pass information from an Attachment to a Raster or vice versa.
Jan Šlegr said:Why you want to do something else than how VBA API is designed? Plus, why do you want to remove an element? Element must exist (which means, because we are discussing programming API, the object must exist in memory), but it does not require it must be persisted in DGN file.
I was trying to replicate the functionality when using the References Dialog box which is quite simple . i.e. Right Click Reference > Clip > Select Block & Clip Boundary from the Options Box.
I have multiple files to do the same thing with the same points to clip so thought that a bit of code would be the way to go.
Jan Šlegr said:Did you test how the method works? The code is simple:
I haven't tested the method or creating an element as I thought if there was a way to do it by points it would make the idea of creating an element redundant.
But that's cool, you learn something new every day, that's what this site is all about thanks for your help. Ill use the Element method.
Robert Golding said:so I thought there might have been a common way to do either, or to pass information from an Attachment to a Raster or vice versa.
Unfortunately, I think because of their history, vector and raster attachments are different (they are stored differently in DGN), so also API works in different way.
Regards,
Robert Golding said:The original post asked about Clipping Raster
The title of your first post is Set Clip Boundary by Points. I leaped to the wrong conclusion.