CVEV 118/698 AutoCAD VBA Lecture 3 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar.

Slides:



Advertisements
Similar presentations
Intro to Scala Lists. Scala Lists are always immutable. This means that a list in Scala, once created, will remain the same.
Advertisements

Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
Modeling using VBA. Covered materials -Userforms -Controls -Module -Procedures & Functions -Variables -Scope.
VBA for MS Excel Hamze Msheik. Open the Visual Basic Editor in Excel 2007 Click on the Microsoft Office button in the top left of the Excel window and.
VBA Modules, Functions, Variables, and Constants
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
CVEV 118/698 Visual Basic Lecture 2 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar.
CVEV 118/698 Visual Basic Lecture 1 Prof. Mounir Mabsout Expert 1: Elsa Sulukdjian Expert 2: Walid El Asmar.
CVEV 118/698 AutoCAD VBA Lecture 1 Prof. Mounir Mabsout
CVEV 118/698 AutoCAD VBA Lecture 2 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar.
CVEV 118/698 Active Server Pages Lecture 3 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar.
CSI 101 Elements of Computing Spring 2009 Lecture # 8 Looping and Recursion Wednesday, February 25 th, 2009.
1 CS 201 Passing Function as Parameter & Array Debzani Deb.
CVEV 118/698 Visual Basic Lecture 3 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
Introducing Hashing Chapter 21 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Python Control of Flow.
Java Unit 9: Arrays Declaring and Processing Arrays.
IE 212: Computational Methods for Industrial Engineering
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Chapter 17: Arrays Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
Comparing AlgorithmsCSCI 1900 – Discrete Structures CSCI 1900 Discrete Structures Complexity Reading: Kolman, Sections 4.6, 5.2, and 5.3.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
Arrays and 2D Arrays.  A Variable Array stores a set of variables that each have the same name and are all of the same type.  Member/Element – variable.
© 2012 EMC Publishing, LLC Slide 1 Chapter 8 Arrays  Can store many of the same type of data together.  Allows a collection of related values to be stored.
 2005 Pearson Education, Inc. All rights reserved. 1 Arrays Part 4.
Chapter 8: Arrays.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
Arrays Group of variables that have a similar type
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Roles of Variables with Examples in Python ® © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.
‘Tirgul’ # 3 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #3.
M180: Data Structures & Algorithms in Java Arrays in Java Arab Open University 1.
Enhanced For Loops (For Each Loops) Less Code and Less Overhead for Writing For Loops.
Scope When we create variables and functions, they are limited in where they are visible and where they can be referenced For the most part, the identifiers.
CS320n –Visual Programming
Hashing as a Dictionary Implementation Chapter 19.
Lab 6 (2) Arrays ► Lab 5 (1) Exercise Review ► Array Concept ► Why Arrays? ► Array Declaration ► An Example of Array ► Exercise.
Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 9 Arrays  Read Bishop, Sections 6.1 to 6.3.  Homework #9 and Lab #9 due next week.  Quiz #5 next.
CHAPTER 9 PART II. MULTIDIMENSIONAL ARRAYS Used to represent tables of values arranged in rows and columns. Table element requires two indexes: row and.
Beginning Fortran Introduction 13 October 2009 *Black text on white background provided for easy printing.
COMPUTER PROGRAMMING 2 ArrayLists. Objective/Essential Standard Essential Standard 3.00Apply Advanced Properties of Arrays Essential Indicator 3.02 Apply.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
Visual C# 2005 Using Arrays. Visual C# Objectives Declare an array and assign values to array elements Initialize an array Use subscripts to access.
Visual Basic CDA College Paphos Campus COM123 Visual Programming 1 Lecture: Charalambous Sotiris Week 8: COM123 Visual Programming 1 Lecture: Charalambous.
1 st Semester Module 7 Arrays อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering Department.
Chapter 9 Introduction to Arrays Fundamentals of Java.
Today… Preparation for doing Assignment 1. Invoking methods overview. Conditionals and Loops. Winter 2016CMPE212 - Prof. McLeod1.
Save Our Source! Converting VBA to VB.NET Mary West Senior Software Developer, Avatech Solutions.
Entry Task Circles and Arcs What is a circle? Circle The set of all points in a plane that are the same distance from a given point (this point.
1 Structures & Unions. 2 User-Defined Types C provides facilities to define one’s own types. These may be a composite of basic types ( int, double, etc)
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
Arrays 1.
VBA - Excel VBA is Visual Basic for Applications
Good practices that help minimize the need for debugging
Sequences and Indexing
Arrays: Checkboxes and Textareas
Data Structures Interview / VIVA Questions and Answers
Topics The if Statement The if-else Statement Comparing Strings
Week 9 – Lesson 1 Arrays – Character Strings
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
Chapter (3) - Looping Questions.
STL - Algorithms.
Introduction to Problem Solving and Control Statements
Presentation transcript:

CVEV 118/698 AutoCAD VBA Lecture 3 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

For iterating through a selection set, the For-Each- Next loop structure may not be best at all times. For iterating through a selection set, the For-Each- Next loop structure may not be best at all times. Example: when selectively removing objects from the selection set. The For-Each-Next loop starts at the beginning of the list till the end of it and the removal of an item from the list inside the loop will cause the loop to skip one. 2 alternative ways of solving this problem: 2 alternative ways of solving this problem: – Using an array containing the object references to the items to be removed from the set. After the loop remove items with the RemoveItems method. – Remove items as found but within a While loop that starts at the back of the collection and working forward. Selection Set Collection Iterations

Object Removal from Selection Set – Example 1 Selection set filter 1: Array containing object references to items to be removed from selection set: Sub My_Filter1(SS As AcadSelectionSet, ET As Object) Dim Ents() As Object Dim Ents() As Object Dim Ent As Object Dim Ent As Object i = 0 i = 0 For Each Ent In SS For Each Ent In SS If Ent.EntityType <> ET.EntityType Then If Ent.EntityType <> ET.EntityType Then ReDim Preserve Ents(0 To i) ReDim Preserve Ents(0 To i) Set Ents(i) = Ent Set Ents(i) = Ent i = i + 1 i = i + 1 End If End If Next Ent Next Ent If i > 0 Then If i > 0 Then SS.RemoveItems (Ents) SS.RemoveItems (Ents) End If End If End Sub Note: “Preserve” maintains the values in the array as it is expanded while “ReDim” by itself will destroy the current contents of the array.

Object Removal from Selection Set – Example 2 Selection set filter 2: Removing items from a selection set using a While loop that starts at the back of the collection and working forward: Sub My_Filter2(SS As AcadSelectionSet, ET As Object) Dim Ent(0) As Object Dim Ent(0) As Object i = SS.Count i = SS.Count While (i > 0) While (i > 0) i = i - 1 i = i - 1 Set Ent(0) = SS.Item(i) Set Ent(0) = SS.Item(i) If Ent(0).EntityType <> ET.EntityType Then If Ent(0).EntityType <> ET.EntityType Then SS.RemoveItems (Ents) SS.RemoveItems (Ents) End If End If Wend Wend End Sub

Filtering the Selection Set For selection of specific entity objects in an application, working with subsets, I.e. Selection Sets, makes it easier. For selection of specific entity objects in an application, working with subsets, I.e. Selection Sets, makes it easier. To build a selection set of certain types of objects or objects that share specific property traits, you can use a filter. To build a selection set of certain types of objects or objects that share specific property traits, you can use a filter. A filter is a set of properties that the entity objects need to match in order to be included in the selection set (properties can be specific object types as well as ranges of values – ex: all circles with radii 1 and 2 drawing units). A filter is a set of properties that the entity objects need to match in order to be included in the selection set (properties can be specific object types as well as ranges of values – ex: all circles with radii 1 and 2 drawing units). In VBA, a filter is constructed as 2 arrays of variants containing information that consists of group codes and data values. In VBA, a filter is constructed as 2 arrays of variants containing information that consists of group codes and data values.

The Filter The 1 st array of the filter contains group codes only. The 1 st array of the filter contains group codes only. Group Codes: are integer values that indicate the type of data being referenced. The data itself resides in the 2 nd array. The index value links the 2 arrays (the 1 st value in the group codes array correspond with the 1 st value in the data array). Group Codes: are integer values that indicate the type of data being referenced. The data itself resides in the 2 nd array. The index value links the 2 arrays (the 1 st value in the group codes array correspond with the 1 st value in the data array). The 2 nd array contains the data elements associated with the group codes. The 2 nd array contains the data elements associated with the group codes. Data Elements: will be of different data types that correspond to the integer codes (ex: group code 2 will have a string, group code 10 will have a point). Data Elements: will be of different data types that correspond to the integer codes (ex: group code 2 will have a string, group code 10 will have a point). The 2 arrays MUST then be assigned to variant variables that are passed to the selection set function. The reason for using variants is to ease the transfer of information from BASIC to other environments. The 2 arrays MUST then be assigned to variant variables that are passed to the selection set function. The reason for using variants is to ease the transfer of information from BASIC to other environments.

Most Frequently Used Group Codes Group Code Data Contents 0 Object type string – LINE, ARC, or CIRCLE 1 String value in Text, Mtext 2 Object name string – used for Blocks & Tables 8 Layer name string 10 Primary point 11… Secondary points for text alignments, line endpoints,… 40 Arc and circle radius 62 Color number (integer) 67 Model/Paper space integer flag (value of 1 indicates the object is in paper space) -4 Grouping operator string or relational test (“<=“…)

Filter Selection Example Building a selection set from the entire drawing that will contain only CIRCLE entity objects with a radius of 5 drawing units: Building a selection set from the entire drawing that will contain only CIRCLE entity objects with a radius of 5 drawing units: Dim Ftyp(1) As Integer Dim Ftyp(1) As Integer Dim Fvar(1) As Variant Dim Filter1, Filter2 As Variant Ftyp(0) = 0: Fvar(0) = "CIRCLE" Ftyp(1) = 40: Fvar(1) = 5# Dim S1 As AcadSelectionSet Set S1 = ThisDrawing.SelectionSets.Add("S1") Filter1 = Ftyp 'Filter 1 is the FilterType Filter2 = Fvar 'Filter 2 is the FilterData S1.Select acSelectionSetAll,,, Filter1, Filter2 Arrays must be dimensioned to the proper size for the filters, I.e. if you ‘re using only 2 filter items, the array length should be exactly 2. Arrays must be dimensioned to the proper size for the filters, I.e. if you ‘re using only 2 filter items, the array length should be exactly 2.

Refining Filters – Numeric Tests Selection set containing all circles with a radius value less than or equal to 5 drawing units: Selection set containing all circles with a radius value less than or equal to 5 drawing units: Dim Ftyp1(2) As Integer Dim Fvar1(2) As Variant Dim Filter1, Filter2 As Variant Dim S1 As AcadSelectionSet Ftyp1(0) = 0: Fvar1(0) = "CIRCLE" Ftyp1(1) = -4: Fvar1(1) = "<=" Ftyp1(2) = 40: Fvar1(2) = 5# Set S1 = ThisDrawing.SelectionSets.Add("S1") Filter1 = Ftyp1 'Filter 1 is the FilterType Filter2 = Fvar1 'Filter 2 is the FilterData S1.Select acSelectionSetAll,,, Filter1, Filter2 The filter uses the (-4) group code. The comparison test is applied to the values that follow (here the radius value). The filter uses the (-4) group code. The comparison test is applied to the values that follow (here the radius value).

Numeric Relational Tests These tests are typically applied against real numbers found in entity object properties and they can also be applied for points: These tests are typically applied against real numbers found in entity object properties and they can also be applied for points: =Equal to <Less than >Greater than <=Less than or equal >= Greater than or equal != or /=Not equal to *Always-true returns true very time

Numeric Tests for Points Testing for objects that are located in the 1 st quadrant, I.e. having X and Y values >= 0: Testing for objects that are located in the 1 st quadrant, I.e. having X and Y values >= 0: Dim Pnt(0 To 2) As Double Dim Ftyp(1) As Integer: Dim Fvar(1) As Variant Dim Filter1, Filter2 As Variant Dim S1 As AcadSelectionSet Pnt(0) = 0#: Pnt(1) = 0#: Pnt(2) = 0# Ftyp(0) = -4: Fvar(0) = ">=,>=,*" Ftyp(1) = 10: Fval(1) = Pnt Filter1 = Ftyp 'Filter 1 is the FilterType Filter2 = Fval 'Filter 2 is the FilterData Set S1 = ThisDrawing.SelectionSets.Add("S1") S1.Select acSelectionSetAll,,, Filter1, Filter2

What’s Next More Objects More Objects More Methods More Methods