Good evening,
please see attached files, module: smartDim, sub: Dimension.
If I include IncludeOnlyWithinRange I get no element!
Why?
Thanks a lot,
PaoloSketchesPrinting 2021.04.21 - WIP TO DIM.mvbaSLS180-62 .dgn
Your VBA project contains a number of modules, classes and forms. There are at least three functions that use ElementScanCriteria. Which function is giving you a problem?
ElementScanCriteria
Paolo Maggiani said:If I include IncludeOnlyWithinRange I get no element!
Please post the code where you set up your ScanCriteria.
Regards, Jon Summers LA Solutions
Hi Paolo,
as Jon wrote: It would be better to extract code that does not work than to share complete project, because it makes analysis more complicated (and, in fact, it's not really safe to try to open and run 3rd party macro on own computer).
Paolo Maggiani said:Why?
Because there is a mistake: How Low limit can be bigger than High limit?
myRange.Low.X = 0 myRange.Low.Y = -1009 'wrong myRange.High.X = 2214 myRange.High.Y = -2600 'wrong
In fact, your code is written in a way "I want more such mistakes caused by unreadable code.". Things like defining all variables at the beginning are treated as wrong (it was was necessary more than 20 years ago in some languages, but today it's just a bad habit). Also, when a comment is required, it's probably a proof your code is dirty.
Even when it's still not clean code ("do one thing only" principle is not followed), better is to (A) define variable exactly when is needed and (B) put all related code together:
Sub Dimension() Dim myFilter As New ElementScanCriteria myFilter.ExcludeAllTypes myFilter.ExcludeAllColors myFilter.ExcludeAllLineStyles myFilter.ExcludeAllLineWeights myFilter.IncludeType msdElementTypeLine myFilter.IncludeType msdElementTypeLineString myFilter.IncludeType msdElementTypeArc myFilter.IncludeColor 0 myFilter.IncludeLineStyle ActiveDesignFile.LineStyles("4") myFilter.IncludeLineWeight 0 Dim myRange As Range3d myRange.High.X = 2214 myRange.Low.X = 0 myRange.High.Y = -1009 'Now it's clear it's wrong myRange.Low.Y = -2600 'because High.Y < Low.Y myFilter.IncludeOnlyWithinRange myRange Dim myEnum As ElementEnumerator Set myEnum = ActiveModelReference.Scan(myFilter) While myEnum.MoveNext Dim myAxeElement As Element Set myAxeElement = myEnum.Current MsgBox "Style: " & myAxeElement.LineStyle.Name & vbCrLf & _ vbCrLf & "Weight: " & myAxeElement.LineWeight & vbCrLf & _ "Color: " & myAxeElement.Color & vbCrLf & _ "Cat: " & myAxeElement.Class Wend MsgBox "FINE" End Sub
I think it's also better to use "4" as identification for Line style 4 than to use index value 5, because it's not clear when read that in fact, it's Line Style 4.
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Good evening Jon,
I'll follow your suggestions next times. (I don't post any code this time because Jan already solved the problem.)
Thanks a lot for your interest :-)
Best regards,
Paolo
Good evening Jan,
thanks a lot for your answer.
Jan Šlegr said:Because there is a mistake: How Low limit can be bigger than High limit?
Stupidly, I didn't think it mattered. Sorry...
Furthermore I will also follow your advice slavishly. In fact I "learned" to program about 30/32 years ago (OMG !!!) and now it's just a (small) passion.
Thanks so much for the advice.
Sincerely,Paul