Showing results for 
Show  only  | Search instead for 
Did you mean: 

duplicate class and its attributes

Occasional Contributor

duplicate class and its attributes



I've written a macro in MEGA 2009 that made a copy of an existing class and its attributes. Now I want to use this in HOPEX V2R1.


Sub CmdInvoke (objMega, intCommandNumber)
		Dim aDuplicateObject
		Dim oPackage, iPackage
		Dim PackageId
		'Dim oDiagram
		Dim oAttr, iAttr
		Dim aDuplicateAttribute
		Dim NewName
    Dim ExpType

		oPackage = objMega.getcollection("OwnerPackage")
    if oPackage.count = 1 then
      for each iPackage in oPackage
        NewName = Create_New_Name(objMega.GetProp("Short Name"), iPackage)
        set aDuplicateObject = iPackage.Getcollection("OwnedClass").Create(NewName)
        aDuplicateObject.SetProp "SQLName", objMega.GetProp("SQLName")
        aDuplicateObject.SetProp "Comment", objMega.GetProp("Comment")


				oAttr = objMega.GetCollection("Attribute")
				for each iAttr in oAttr
					set aDuplicateAttribute = aDuplicateObject.GetCollection("Attribute").Add(iAttr.GetProp("Local Name"))

					aDuplicateAttribute.SetProp "Length", iAttr.GetProp("Length")
					aDuplicateAttribute.SetProp "Decimal", iAttr.GetProp("Decimal")
					aDuplicateAttribute.SetProp "SQLName", iAttr.GetProp("SQLName")
					aDuplicateAttribute.SetProp "DEX Enumeration", iAttr.GetProp("DEX Enumeration")
					aDuplicateAttribute.SetProp "Comment", iAttr.GetProp("Comment")
					aDuplicateAttribute.SetProp "Order", iAttr.GetProp("Order")
          ExpType= iAttr.getCollection("TypeClass")
					if exptype.count = 1 then
					end if
      msgbox "niks gevonden"
    end if
End Sub

function Create_New_Name(ClassName, iPackage)

	dim oClass
	dim ClaSuffixCount
  dim strCount
  Dim RetVal
	Dim DQ

	DQ = """"

	BoolNameOk = false

  for ClaSuffixCount = 1 to 9
    if len(ClaSuffixCount) = 1 then
      strCount = "0" & CStr(ClaSuffixCount)
			strCount = CStr(ClaSuffixCount)
    end if

    oClass = iPackage.GetSelection("Select Class where [short name] = " & dq & ClassName & "_" & strCount & dq)
      if oClass.Count = 0 then
        RetVal = ClassName & "_" & strCount
        exit for
      end if
  Create_New_Name = RetVal
end function

This actually works fine, but for 1 thing. The name of the attributes of the class is not correctly set:


Instead of the name (like ID or Aliasname) I get the value "(Uninitialized)"


Anyone any idea what I should change in my code so the name is copied?


2 Replies

Re: duplicate class and its attributes



This may not be related to the script.

Try to create the same data in interactive mode.


There is a known issues about Attribute (DM) in Entity (DM)

See KB


Occasional Contributor

Re: duplicate class and its attributes

Hi Jerome,

thank you for the response. We will discuss the proposed solution.

But given your answer that the name is changed to '(unitialised)' when the data type is changed, i've also tested another workaround:

          ExpType= iAttr.getCollection("TypeClass")
					if exptype.count = 1 then
					end if

					aDuplicateAttribute.SetProp "Local Name", iAttr.GetProp("Local Name")'

 Reset the name after the attributes was connected to the TypeClass.



This also works. So we will see what's the best solution for now.


Kind regards,